1.docker ps介绍
docker ps命令是用来列出容器的相关信息
2.docker ps用法
docker ps [参数]
[root@centos79 ~]# docker ps --helpUsage: docker ps [OPTIONS]List containersAliases:docker container ls, docker container list, docker container ps, docker psOptions:-a, --all Show all containers (default shows just running)-f, --filter filter Filter output based on conditions provided--format string Format output using a custom template:'table': Print output in table format with column headers (default)'table TEMPLATE': Print output in table format using the given Go template'json': Print in JSON format'TEMPLATE': Print output using the given Go template.Refer to https://docs.docker.com/go/formatting/ for more information aboutformatting output with templates-n, --last int Show n last created containers (includes all states) (default -1)-l, --latest Show the latest created container (includes all states)--no-trunc Don't truncate output-q, --quiet Only display container IDs-s, --size Display total file sizes
[root@centos79 ~]#
3.实例
3.1.显示正在运行的容器
命令:
docker ps
[root@centos79 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d59b9e356f74 centos:centos7 "/bin/bash" 49 seconds ago Up 48 seconds condescending_margulis
8cd2c35ffd65 centos:centos7 "/bin/bash" 51 seconds ago Up 50 seconds nervous_mclean
5fffa9ab7380 centos:centos7 "/bin/bash" 52 seconds ago Up 51 seconds xenodochial_moore
800d0759315f centos:centos7 "/bin/bash" 53 seconds ago Up 53 seconds gracious_bohr
425747b4385b centos-nginx:1.0 "nginx -g 'daemon of…" 4 hours ago Up 34 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp centos-nginx
4ad2db28832b logstash:7.11.1 "/usr/local/bin/dock…" 3 weeks ago Up 34 minutes 0.0.0.0:5045->5044/tcp, :::5045->5044/tcp, 0.0.0.0:9601->9600/tcp, :::9601->9600/tcp logstash-messages
eba7697b317c logstash:7.11.1 "/usr/local/bin/dock…" 3 weeks ago Up 34 minutes 0.0.0.0:5044->5044/tcp, :::5044->5044/tcp, 0.0.0.0:9600->9600/tcp, :::9600->9600/tcp logstash
d5dc67cd0596 kibana:7.11.1 "/bin/tini -- /usr/l…" 3 weeks ago Up 34 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana
85374b727101 elasticsearch:7.11.1 "/bin/tini -- /usr/l…" 3 weeks ago Up 34 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp es
[root@centos79 ~]#
3.2.显示所有的容器
命令:
docker ps -a
[root@centos79 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15792fdb6bdc hello-world "/hello" About a minute ago Exited (0) About a minute ago distracted_panini
4a8eb7af634f hello-world "/hello" About a minute ago Exited (0) About a minute ago pedantic_shaw
d59b9e356f74 centos:centos7 "/bin/bash" About a minute ago Up About a minute condescending_margulis
8cd2c35ffd65 centos:centos7 "/bin/bash" About a minute ago Up About a minute nervous_mclean
5fffa9ab7380 centos:centos7 "/bin/bash" About a minute ago Up About a minute xenodochial_moore
800d0759315f centos:centos7 "/bin/bash" About a minute ago Up About a minute gracious_bohr
8f86869d31a8 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago busy_taussig
425747b4385b centos-nginx:1.0 "nginx -g 'daemon of…" 4 hours ago Up 34 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp centos-nginx
4ad2db28832b logstash:7.11.1 "/usr/local/bin/dock…" 3 weeks ago Up 34 minutes 0.0.0.0:5045->5044/tcp, :::5045->5044/tcp, 0.0.0.0:9601->9600/tcp, :::9601->9600/tcp logstash-messages
eba7697b317c logstash:7.11.1 "/usr/local/bin/dock…" 3 weeks ago Up 34 minutes 0.0.0.0:5044->5044/tcp, :::5044->5044/tcp, 0.0.0.0:9600->9600/tcp, :::9600->9600/tcp logstash
d5dc67cd0596 kibana:7.11.1 "/bin/tini -- /usr/l…" 3 weeks ago Up 34 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana
85374b727101 elasticsearch:7.11.1 "/bin/tini -- /usr/l…" 3 weeks ago Up 34 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp es
[root@centos79 ~]#
3.3.显示最近创建的4个容器
命令:
docker ps -n 4
[root@centos79 ~]# docker ps -n 4
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15792fdb6bdc hello-world "/hello" About a minute ago Exited (0) About a minute ago distracted_panini
4a8eb7af634f hello-world "/hello" About a minute ago Exited (0) About a minute ago pedantic_shaw
d59b9e356f74 centos:centos7 "/bin/bash" 2 minutes ago Up 2 minutes condescending_margulis
8cd2c35ffd65 centos:centos7 "/bin/bash" 2 minutes ago Up 2 minutes nervous_mclean
[root@centos79 ~]#
3.4.正在运行的容器ID
命令:
docker ps -q
[root@centos79 ~]# docker ps -q
d59b9e356f74
8cd2c35ffd65
5fffa9ab7380
800d0759315f
425747b4385b
4ad2db28832b
eba7697b317c
d5dc67cd0596
85374b727101
[root@centos79 ~]#
3.5.显示所有容器ID
命令:
docker ps -qa
[root@centos79 ~]# docker ps -aq
15792fdb6bdc
4a8eb7af634f
d59b9e356f74
8cd2c35ffd65
5fffa9ab7380
800d0759315f
8f86869d31a8
425747b4385b
4ad2db28832b
eba7697b317c
d5dc67cd0596
85374b727101
[root@centos79 ~]#
3.6.显示完整形式的容器ID
命令:
docker ps -aq --no-trunc
[root@centos79 ~]# docker ps -aq --no-trunc
15792fdb6bdca4e36adba5cf40ce35cfab2621dddd121da8d739b4fb39216a1e
4a8eb7af634f844a302a3a0559b873d8030e7f5fd613818150ee720cec3dded2
d59b9e356f7406f043f5ca071bda6c28240d4e32c0db851cc52ecccfbebc9016
8cd2c35ffd658c50ea2e1880bed7a73679b32fce2910cb7434f98ef461242a95
5fffa9ab7380cef48008f57acc41af14904edf2720bb140e15f0bd3efea6382e
800d0759315f6b3f89129824cb541d00e2491318b88bcc1bacbb2b1f8c6103c8
8f86869d31a8b3cdad8695d9437d5c1e017ab690283f1b3b96d3f20a2a58a0ca
425747b4385b2198f27d70a371dd586967cf105994acd0b9a3eaa2fecb4c7ad0
4ad2db28832b91d67042e3556a0f9bbe9df886782b837833cca6b42a554a5ff2
eba7697b317c0a8be4ccfe2fe825fa37e1d45ec862c6a816af96629734e74843
d5dc67cd0596859522fa0cdd7882e24a6d8466646459a81542875a4bc27767c7
85374b727101b988a20dc7ba0bc84a7d4429e144346bae5c23ec2ff7db11666a
[root@centos79 ~]#
3.7.显示容器大小
命令:
docker ps -s
[root@centos79 ~]# docker ps -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
d59b9e356f74 centos:centos7 "/bin/bash" 5 minutes ago Up 5 minutes condescending_margulis 0B (virtual 204MB)
8cd2c35ffd65 centos:centos7 "/bin/bash" 5 minutes ago Up 5 minutes nervous_mclean 0B (virtual 204MB)
5fffa9ab7380 centos:centos7 "/bin/bash" 5 minutes ago Up 5 minutes xenodochial_moore 0B (virtual 204MB)
800d0759315f centos:centos7 "/bin/bash" 5 minutes ago Up 5 minutes gracious_bohr 0B (virtual 204MB)
425747b4385b centos-nginx:1.0 "nginx -g 'daemon of…" 4 hours ago Up 38 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp centos-nginx 1.35kB (virtual 449MB)
4ad2db28832b logstash:7.11.1 "/usr/local/bin/dock…" 3 weeks ago Up 38 minutes 0.0.0.0:5045->5044/tcp, :::5045->5044/tcp, 0.0.0.0:9601->9600/tcp, :::9601->9600/tcp logstash-messages 5.3MB (virtual 969MB)
eba7697b317c logstash:7.11.1 "/usr/local/bin/dock…" 3 weeks ago Up 38 minutes 0.0.0.0:5044->5044/tcp, :::5044->5044/tcp, 0.0.0.0:9600->9600/tcp, :::9600->9600/tcp logstash 5.3MB (virtual 969MB)
d5dc67cd0596 kibana:7.11.1 "/bin/tini -- /usr/l…" 3 weeks ago Up 38 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana 259B (virtual 1.01GB)
85374b727101 elasticsearch:7.11.1 "/bin/tini -- /usr/l…" 3 weeks ago Up 38 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp es 3.78MB (virtual 823MB)
[root@centos79 ~]#
返回结果中多了一列SIZE,SIZE有两个值(E.g:3.78MB (virtual 823MB)--样例来自输出的最后一行),其中,3.78MB为容器真实增加的大小,virtual 823MB为整个容器虚拟大小。
整个容器虚拟大小的计算方法:
整个容器虚拟大小 = 容器真实增加的大小 + 容器镜像大小
3.8.按条件过滤容器
-->查找id为800d的容器
命令:
docker ps --filter id=800d
[root@centos79 ~]# docker ps --filter id=800d
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
800d0759315f centos:centos7 "/bin/bash" 12 minutes ago Up 12 minutes gracious_bohr
[root@centos79 ~]#
-->查找id为800d或5fff的容器
命令:
docker ps --filter id=800d --filter id=5fff
备注:相同条件之间的关系是“或”关系
[root@centos79 ~]# docker ps --filter id=800d --filter id=5fff
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5fffa9ab7380 centos:centos7 "/bin/bash" 14 minutes ago Up 14 minutes xenodochial_moore
800d0759315f centos:centos7 "/bin/bash" 14 minutes ago Up 14 minutes gracious_bohr
[root@centos79 ~]#
-->查找id为800d并且name为gracious_bohr的容器
命令:
docker ps --filter id=800d --filter name=gracious_bohr
备注:不同条件之间的关系是“与”关系
[root@centos79 ~]# docker ps --filter id=800d --filter name=gracious_bohr
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
800d0759315f centos:centos7 "/bin/bash" 15 minutes ago Up 15 minutes gracious_bohr
[root@centos79 ~]#
-->模糊匹配容器
命令:
docker ps --filter name=^/gracious.*
[root@centos79 ~]# docker ps --filter name=^/gracious.*
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
800d0759315f centos:centos7 "/bin/bash" 24 minutes ago Up 24 minutes gracious_bohr
[root@centos79 ~]#