docker ps
Table of Contents:
Command Name:
docker ps
Description:
list containers
Syntax:
easywhatis$ 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
-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 numeric IDs
-s, --size Display total file sizes
easywhatis$
Example:
List all containers
docker ps
easywhatis$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
easywhatis$
Show both running and stopped containers
easywhatis$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
83f356c86d70 77e7666f2e5f "/bin/sh -c 'apt-get..." 8 hours ago Exited (1) 8 hours ago cool_allen
22ff3c787a57 a7fa4ac97be4 "catalina.sh run" 4 days ago Exited (255) 2 days ago 0.0.0.0:8080->8080/tcp tomcat
easywhatis$
Show disk usage by container including stopped container
easywhatis$ docker ps -a -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
83f356c86d70 77e7666f2e5f "/bin/sh -c 'apt-get..." 8 hours ago Exited (1) 8 hours ago cool_allen 0B (virtual 92.4MB)
22ff3c787a57 a7fa4ac97be4 "catalina.sh run" 4 days ago Exited (255) 2 days ago 0.0.0.0:8080->8080/tcp tomcat 9.89kB (virtual 528MB)
Use of –filter:
docker ps –a —filter “label=maintainer”
Note: To get the labels of any particular container use docker inspect command.
easywhatis$ docker inspect nginx
[
{
"Id": "sha256:ed21b7a8aee9cc677df6d7f38a641fa0e3c05f65592c592c9f28c42b3dd89291",
"RepoTags": [
"nginx:latest"
],
"RepoDigests": [
"nginx@sha256:282530fcb7cd19f3848c7b611043f82ae4be3781cb00105a1d593d7e6286b596"
],
"Parent": "",
"Comment": "",
"Created": "2020-03-31T03:19:30.487069362Z",
"Container": "5c86b143cf5caec0aed5c331922c243f00600152ec0e9ecbe8531771562e72b8",
"ContainerConfig": {
"Hostname": "5c86b143cf5c",
"Domainname": "",
"User": "",
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“80/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“NGINX_VERSION=1.17.9”,
“NJS_VERSION=0.3.9”,
“PKG_RELEASE=1~buster”
],
“Cmd”: [
“/bin/sh”,
“-c”,
“#(nop) “,
“CMD [\”nginx\” \”-g\” \”daemon off;\“]”
],
“ArgsEscaped”: true,
“Image”: “sha256:9be1fc3b00d81a66f4de11f5f5bf176e0748434be056cf3152386cc917307e7f”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“maintainer”: “NGINX Docker Maintainers <docker-maint@nginx.com>”
},
“StopSignal”: “SIGTERM”
},
“DockerVersion”: “18.09.7”,
“Author”: “”,
“Config”: {
“Hostname”: “”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“80/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“NGINX_VERSION=1.17.9”,
“NJS_VERSION=0.3.9”,
“PKG_RELEASE=1~buster”
],
“Cmd”: [
“nginx”,
“-g”,
“daemon off;”
],
“ArgsEscaped”: true,
“Image”: “sha256:9be1fc3b00d81a66f4de11f5f5bf176e0748434be056cf3152386cc917307e7f”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“maintainer”: “NGINX Docker Maintainers <docker-maint@nginx.com>”
},
“StopSignal”: “SIGTERM”
},
“Architecture”: “amd64”,
“Os”: “linux”,
“Size”: 126769107,
“VirtualSize”: 126769107,
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay2/69da490a856391c0dc1994d9c0ac5c46571414a102ebca66b6a5a623c3b09291/diff:/var/lib/docker/overlay2/ba81d1c0826af5615edc5083c814c7daccb6f0569e3b91a6030002e362aeb3a0/diff”,
“MergedDir”: “/var/lib/docker/overlay2/80c0e7309e24b0f777d38275c1d83b7cede2778c1c5bf7659fea3c32aabdd5d4/merged”,
“UpperDir”: “/var/lib/docker/overlay2/80c0e7309e24b0f777d38275c1d83b7cede2778c1c5bf7659fea3c32aabdd5d4/diff”,
“WorkDir”: “/var/lib/docker/overlay2/80c0e7309e24b0f777d38275c1d83b7cede2778c1c5bf7659fea3c32aabdd5d4/work”
},
“Name”: “overlay2”
},
“RootFS”: {
“Type”: “layers”,
“Layers”: [
“sha256:c3a984abe8a88059915bb6c7a1d249fd1ccc16d931334ac8816540b0eb686b45”,
“sha256:99134ec7f247e5a211c7205fec587bf72a6d4aac339b21858b892e9c04f78920”,
“sha256:d37eecb5b7691ec21bd19989e37f8bb4d20b340a775591d0f3db5897d606b0e4”
]
},
“Metadata”: {
“LastTagTime”: “0001-01-01T00:00:00Z”
}
}
]
easywhatis$
easywhatis$ docker ps -a --filter "label=maintainer"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
03bbc2ef54bf nginx "nginx -g 'daemon of..." 53 seconds ago Up 51 seconds 0.0.0.0:8080->80/tcp some-nginx
88843f276424 nginx "--it -p 8080:8080 n..." 2 minutes ago Created 80/tcp affectionate_hermann
2e6784a86d22 nginx "-it -p 8080:8080 ng..." 2 minutes ago Created 80/tcp sharp_napier
90516225cbe6 nginx "-it -p 8080:8080 ng..." 2 minutes ago Created 80/tcp exciting_swanson
77735210dc15 nginx "nginx -g 'daemon of..." 3 minutes ago Up 3 minutes 80/tcp practical_solomon
docker ps –a —filter expose=8080
easywhatis$ docker ps -a --filter "expose=8080"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22ff3c787a57 a7fa4ac97be4 "catalina.sh run" 4 days ago Exited (255) 2 days ago
0.0.0.0:8080->8080/tcp tomcat