The docker system command

Hello again! This article talks about how to get general information about the whole docker system and do “cleanup” of containers, images and volumes with docker system.

Docker system

The docker system command has several subcommands:

• docker system info
• docker system df
• docker system events
• docker system prune

View docker host information

To see the information about the host from docker we can run the command docker system info or its abbreviation docker info like this:

[ger-pc ~]# docker info
Client:
Debug Mode: false

Server:
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 5
Server Version: 19.03.7-ce
Storage Driver: overlay2
Backing Filesystem: <unknown>
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d76c121f76a5fc8a462dc64594aea72fe18e1178.m
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.5.8-1-MANJARO
Operating System: Manjaro Linux
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.233GiB
Name: ger-pc
ID: MWH3:24AM:UAZJ:E5UL:TRI3:F4NZ:Y3JD:IMKP:7G2V:VV6I:L5XF:J2TW
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

This way we will be able to know on which hardware, docker version, system characteristics, we are working on.

View disk usage of each container

We can see the disk capacity used by each image, container, volume and build cache. The docker system df command will give us a brief summary of the disk for each docker component as you can see in the following example:

[ger-pc ~]# docker system df 
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 6 1 1.006GB 803.4MB (79%)
Containers 1 0 2B 2B (100%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
[ger-pc ~]#

If we also want to know how much disk space each image or each container or each volume occupies, we have to add the -v option to the command as you can see in the following example:

 
[ger-pc ~]# docker system df -v
Images space usage:

REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
nginx alpine 89ec9da68213 3 days ago 19.94MB 0B 19.94MB 0
archlinux latest 9651b9e35f39 2 weeks ago 412.2MB 0B 412.2MB 0
ubuntu 18.04 4e5021d210f6 5 weeks ago 64.21MB 0B 64.21MB 0
centos 8 470671670cac 3 months ago 237.1MB 0B 237.1MB 0
ubuntu 19.04 c88ac1f841b7 3 months ago 69.99MB 0B 69.99MB 0
centos 7 5e35e350aded 5 months ago 203MB 0B 203MB 1

Containers space usage:

CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
6e034771f891 centos:7 "/bin/bash" 0 2B 25 hours ago Exited (137) 15 hours ago container1

Local Volumes space usage:

VOLUME NAME LINKS SIZE

Build cache usage: 0B

CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
[ger-pc ~]#

View disk usage of each container

The docker system events command reports docker system events in real time. This can help us when the system has a failure and we want to prevent it from reoccurring.
The command syntax is very simple:

docker system events

 

Remove docker residues

Docker has a very fast way to clean up the system.
The docker system prune command can help us a lot to perform the system cleanup,

The syntax of the command is:

docker system prune

An example of the output is:

[ger-pc ~]# docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
6e034771f891225529dc6fc7eef6f40d537820d7607f68885edc10f2c71c6f9d

Total reclaimed space: 2B
[ger-pc ~]#

As you can see it will only eliminate:

  • Stopped containers
  • Unused nets (no containers)
  • Images hung
  • Build cache hung

To not ask for confirmation we add the -f parameter so it should be “docker system prune -f” and so it will delete all of the above at once, without confirmation,

If we want to delete all the images we can execute the command by adding -a and the command will look like this:

docker system prune -a

To remove volumes as well, add the –volumes parameter as in the following example:

docker system prune --volumes

 

If you are interested in learning Docker you can purchase our book here

Docker para novatos

Docker para novatos - Gerardo G. Urtiaga-portada-web

If you liked the article, share it on your social networks so we can reach more people!

Best regards

Leave a Reply