Docker commands to survive

Docker commands to survive

docker ps –size

An important command which I discovered and use is docker ps --size.
Its show what is the size of the container.

[dyego@fedora-asus ~]$ docker ps --size
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
dbffabfb478a docker:17.05-dind "dockerd-entrypoin..." 4 weeks ago Up About a minute 2375/tcp docker1705-dind 10.2MB (virtual 110MB)

On this case, you can see the column size which show 10.2MB (virtual 110MB). Compare with the output of docker images:

[dyego@fedora-asus ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker 17.05-dind b547d892dffa 4 weeks ago 99.6MB

We discover the virtual size is the sum of image size + 10.2MB (this space was used creating a file with dd command).

The slice (or slices) that compose the base image is not used for each instance that you run with docker, only the the difference will be stored on the hard disk.
In this case represented by 10.2MB.

free space used by docker containers and images

[dyego@fedora-asus ~]$ docker rm $(docker ps -aq)
[dyego@fedora-asus ~]$ docker rmi $(docker images -aq)
[dyego@fedora-asus ~]$ docker volume rm $(docker volume ls -q)

Inspect a container and discover its pid

If you have any PID that you saw using a lot of resource (like CPU or memory), use this command to inspect all
running dockers and its respective PID - ID - NAME.

[dyego@fedora-asus docker]$ docker ps -q | xargs docker inspect --format '{{.State.Pid}}|{{.ID}}|{{.Name}}'
5746|413810b0c00fe51ac616205db90db222915410202263dc1d2493de5916146534|/test1
4383|dbffabfb478adb2755d5574f586e2250e63dd602bba7706bb2e79252096f036e|/docker1705-dind