不同版本的docker命令会有稍微区别,本次docker版本为
Docker version 17.06.2-ce, build cec0b72
查看docker ps帮助
[root@localhost ~]# docker ps --help
Usage: docker ps [OPTIONS]
List containers
Options:
-a, --all Show all containers (default shows just running) [显示所有运行中的容器]
-f, --filter filter Filter output based on conditions provided 【过滤容器】
--format string Pretty-print containers using a Go template 【使用go模板打印输出】
--help Print usage
-n, --last int Show n last created containers (includes all states) (default -1) 【显示最后创建的n个容器】
-l, --latest Show the latest created container (includes all states)【显示所有最后创建的容器】
--no-trunc Don't truncate output 【不截断输出,完整显示】
-q, --quiet Only display numeric IDs 【显示容器id】
-s, --size Display total file sizes 【显示容器大小】
[root@localhost ~]#
docker ps
默认显示运行中的容器,如果需要查看所有容器需要增加 -a选项
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c95b7f218bd5 dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1
171401662b68 danginx:latest "nginx -g 'daemon ..." 24 hours ago Up 24 hours 0.0.0.0:8083->80/tcp mzcqjy_mzcqjynginx_1
docker ps -a
显示所有容器包括退出状态的
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c95b7f218bd5 dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1
171401662b68 danginx:latest "nginx -g 'daemon ..." 24 hours ago Up 24 hours 0.0.0.0:8083->80/tcp mzcqjy_mzcqjynginx_1
06437e163751 mysql:5.6 "docker-entrypoint..." 24 hours ago Up 24 hours 0.0.0.0:3306->3306/tcp mzcqjy_mysql_1
af0c3e19033c dajdk:latest "java -Djava.secur..." 24 hours ago Up 39 minutes 0.0.0.0:5003->5003/tcp mzcqjy_mzcqjyjava_1
af584030a3ef daredis:3.2.9 "docker-entrypoint..." 24 hours ago Up 24 hours 0.0.0.0:6379->6379/tcp mzcqjy_daredis_1
0375d08222b6 local_seafile/server:latest "/sbin/my_init -- ..." 2 days ago Exited (2) 7 seconds ago seafile
[root@localhost ~]#
docker ps -n 2
显示最后创建的2个容器
seafile
[root@localhost ~]# docker ps -n 2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c95b7f218bd5 dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1
171401662b68 danginx:latest "nginx -g 'daemon ..." 24 hours ago Up 24 hours 0.0.0.0:8083->80/tcp mzcqjy_mzcqjynginx_1
[root@localhost ~]#
docker ps -l
显示最后创建的容器,包括所有状态
[root@localhost ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c95b7f218bd5 dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1
[root@localhost ~]#
docker ps --no-trunc
不截断输出,展示完整信息,默认是省略了一些内容
[root@localhost ~]# docker ps --no-trunc -l #完全展示
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c95b7f218bd5da32554383a66426ba24d338315a23027d0946e7d7b9cf4c261a dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1
[root@localhost ~]# docker ps -l #默认省略了一些内容
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c95b7f218bd5 dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1
[root@localhost ~]#
docker ps -q
显示容器的id
[root@localhost ~]# docker ps -q
c95b7f218bd5
171401662b68
06437e163751
af0c3e19033c
af584030a3ef
[root@localhost ~]#
docker ps -s
显示容器的大小
af584030a3ef
[root@localhost ~]# docker ps -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
c95b7f218bd5 dabuild:latest "/usr/sbin/sshd -D" 20 hours ago Up 20 hours 0.0.0.0:5004->5004/tcp, 0.0.0.0:8011->8011/tcp, 0.0.0.0:8022->8022/tcp dabuilder_dabuild_1 56.5kB (virtual 808MB)
171401662b68 danginx:latest "nginx -g 'daemon ..." 24 hours ago Up 24 hours 0.0.0.0:8083->80/tcp mzcqjy_mzcqjynginx_1 2B (virtual 20.2MB)
06437e163751 mysql:5.6 "docker-entrypoint..." 24 hours ago Up 24 hours 0.0.0.0:3306->3306/tcp mzcqjy_mysql_1 0B (virtual 298MB)
af0c3e19033c dajdk:latest "java -Djava.secur..." 24 hours ago Up About an hour 0.0.0.0:5003->5003/tcp mzcqjy_mzcqjyjava_1 32.8kB (virtual 439MB)
af584030a3ef daredis:3.2.9 "docker-entrypoint..." 24 hours ago Up 24 hours 0.0.0.0:6379->6379/tcp mzcqjy_daredis_1 0B (virtual 20.5MB)
[root@localhost ~]#
docker ps --filter name='mzcqjy_mzcqjyjava_1'
过滤容器名称为mzcqjy_mzcqjyjava_1的容器
[root@localhost ~]# docker ps --filter name='mzcqjy_mzcqjyjava_1'
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
af0c3e19033c dajdk:latest "java -Djava.secur..." 24 hours ago Up About an hour 0.0.0.0:5003->5003/tcp mzcqjy_mzcqjyjava_1
[root@localhost ~]#