Docker命令-ps

命令

docker ps

描述

List containers
显示容器

用法

1
docker ps [OPTIONS]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Options:
--all , -a 显示所有容器,默认只显示运行的容器
--filter , -f 过滤显示
--format 指定显示格式
--last , -n 显示n个已创建的容器,包括所有状态,默认为-1,即最后一个创建的容器
--latest , -l 显示最后一个创建的容器
--no-trunc 不要截断显示
--quiet , -q 只显示容器ID
--size , -s 显示文件大小

--filter
Filter Description
id Container’s ID
name Container’s name
label An arbitrary string representing either a key or a key-value pair. Expressed as <key> or <key>=<value>
exited An integer representing the container’s exit code. Only useful with --all.
status One of created, restarting, running, removing, paused, exited, or dead
ancestor Filters containers which share a given image as an ancestor. Expressed as <image-name>[:<tag>], <image id>, or <image@digest>
before or since Filters containers created before or after a given container ID or name
volume Filters running containers which have mounted a given volume or bind mount.
network Filters running containers connected to a given network.
publish or expose Filters containers which publish or expose a given port. Expressed as <port>[/<proto>] or <startport-endport>/[<proto>]
health Filters containers based on their healthcheck status. One of starting, healthy, unhealthy or none.
is-task Filters containers that are a “task” for a service. Boolean option (true or false)

--format
.ID Container ID
.Image Image ID
.Command Quoted command
.CreatedAt Time when the container was created.
.RunningFor Elapsed time since the container was started.
.Ports Exposed ports.
.State Container status (for example; “created”, “running”, “exited”).
.Status Container status with details about duration and health-status.
.Size Container disk size.
.Names Container names.
.Labels All labels assigned to the container.
.Label Value of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}'
.Mounts Names of the volumes mounted in this container.
.Networks Names of the networks attached to this container.

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ docker ps
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ce2a0c049f9f demo_nginx:v1 "/docker-entrypoint.…" 3 days ago Exited (0) 22 hours ago aaa
a8c31015e674 nginx:1.20.1-alpine "/docker-entrypoint.…" 4 days ago Up 29 seconds 0.0.0.0:80->80/tcp nginx
$ docker ps -s
$ docker ps --filter "label=color"
$ docker ps --filter "label=color=blue"
$ docker ps --filter "name=nginx"
$ docker ps -a --filter 'exited=0'
$ docker ps -a --filter 'exited=137'
$ docker ps --filter status=running
$ docker ps --filter ancestor=ubuntu
$ docker ps -f before=9c3527ed70ce
$ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
$ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
$ docker run -d --net=net1 --name=test1 ubuntu top
$ docker ps --filter network=net1
$ docker run -d --publish=80 busybox top
$ docker run -d --expose=8080 busybox top
$ docker ps --filter publish=80
$ docker ps --filter expose=8000-8080/tcp

$ docker ps --format "{{json .}}"
$ docker ps --format "{{.ID}}: {{.Command}}"
$ docker ps --format "table {{.ID}}\t{{.Labels}}"
$ docker ps -a --format "{{.ID}}: {{.Names}}"
ce2a0c049f9f: aaa
a8c31015e674: nginx
$ docker ps -a --format "{{.ID}}, {{.Names}}, {{.Image}}"
2992db1b41c7, vaultwarden, vaultwarden/server:1.24.0
ce2a0c049f9f, aaa, demo_nginx:v1
a8c31015e674, nginx, nginx:1.20.1-alpine

$ docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Status}}"
CONTAINER ID NAMES PORTS STATUS
2992db1b41c7 demo 0.0.0.0:443->443/tcp, 0.0.0.0:8080->80/tcp Up 4 hours (healthy)
ce2a0c049f9f aaa 80/tcp Up 3 hours
a8c31015e674 nginx 0.0.0.0:80->80/tcp Up 3 hours