Skip to content

Instantly share code, notes, and snippets.

@mkfares
Created August 17, 2020 18:14
Show Gist options
  • Save mkfares/3c84888a99ead5bb297ca38baba2712c to your computer and use it in GitHub Desktop.
Save mkfares/3c84888a99ead5bb297ca38baba2712c to your computer and use it in GitHub Desktop.
Docker System Management

Docker System Management

The docker system commands manage the docker system. It has the following syntax:

$ docker system <command> [options]

Show disk usage

The df command shows the disk space used by the docker daemon. It includes information about images, containers, volumes, and caches. Docker networks are not shown since they do not consume storage space.

$ docker system df

To get more details about the disk usage, use the -v flag.

$ docker system df -v

The columns in the output have the following meanings:

  • SHARED SIZE is the amount of space that an image shares with another one.
  • UNIQUE SIZE is the amount of space that is only used by a given image.
  • SIZE is the total virtual size of the image, it is the sum of SHARED SIZE and UNIQUE SIZE.

Show system-wide information

The info command displays general information about the system.

$ docker system info

The -f flag allows you to display a sepecific information.

$ docker system info -f '{{.ServerVersion}}'
$ docker system info -f '{{.Plugins.Network}}'
$ docker system info -f '{{index .Plugins.Network 1}}'

Remove docker objects

The command prune removes all unused containers, networks, images (both dangling and unreferenced). The command displays the objects to be removed and prompts for confirmation before the removal.

$ docker system prune [options]
$ docker system prune

Options:
-a : Removes all unused images
-f : Removes resources without conformation
--volumes: Also removes volumes

Show system events

The command events displays the events generated by the docker engine. An event is generated when an action is performed on a docker object. Docker objects includes containers, images, volumes, plugins, networks, and docker daemons. For instance, the event "start" is reported when a container starts.

To show the generated events, you need to open two terminal windows. On the first terminal executes the system events command:

# Terminal 1
$ docker system events

On the second terminal window, type the command to start a container:

# Terminal 2
$ docker run --rm --name myalpine alpine

After starting a container, multiple events will show on the first terminal such as image pull, container create, container attach, network connect, container start, container die, network disconnect, and container destroy.

You may filter events by using the -f flag. For instance, to display the die event for the container myalpine, use the following command:

# Terminal 1
$ docker system events -f container=myalpine -f event=die

To limit the display to pull event from all mages, use the following command:

# Terminal 1
$ docker system events -f type=image -f event=pull

To stop listening for events on the first terminal, type the key combination: Ctrl + c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment