Use of docker system command set

Use of docker system command set

Docker system currently has four subcommands, namely:

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

One of the most important commands of the docker system is the docker system prune command, which cleans up unused data, including image data and stopped containers.

See docker system help

[root@localhost ~]# docker system --help

Usage: docker system COMMAND

Manage Docker

Options:
      --help Print usage

Commands:
  df Show docker disk usage
  events Get real time events from the server
  info Display system-wide information
  prune Remove unused data

Run 'docker system COMMAND --help' for more information on a command.
[root@localhost ~]# 

docker system df

Provides an overview of overall Docker disk usage, including images, containers, and (local) volumes. So now we can check at any time how much resources Docker is using.

[root@localhost ~]# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 10 6 2.652GB 1.953GB (73%)
Containers 6 6 6.922MB 0B (0%)
Local Volumes 0 0 0B 0B
[root@localhost ~]# 

docker system prune

If the previous command shows that docker has taken up too much space, we will start cleaning it up. There is a command that does it all:

[root@localhost ~]# docker system prune
WARNING! This will remove:
        - all stopped containers # Clean up stopped containers - all networks not used by at least one container # Clean up unused networks - all dangling images # Clean up abandoned images - all build cache # Clean up the build cache Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
[root@localhost ~]#

According to the warning message, this command will delete all closed containers and dangling images. In the example, the image containing three 1GB random files has a name that is occupied:, which is a dangling image and will be deleted. At the same time, all intermediate images will be deleted.

Going a step further, use the -a option to do a deeper cleanup. At this time we will see more serious WARNING information:

$ docker system prune -a
WARNING! This will remove:
        - all stopped containers
        - all volumes not used by at least one container
        - All networks not used by at least one container
        - all images without at least one container associated to them
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: test:latest
deleted: sha256:c515ebfa2...
deleted: sha256:07302c011...
deleted: sha256:37c0c6474...
deleted: sha256:5cc2b6bc4...
deleted: sha256:b283b9c35...
deleted: sha256:8a8b9bd8b...
untagged: alpine:latest
untagged: alpine@sha256:58e1a1bb75db1...
deleted: sha256:4a415e366...
deleted: sha256:23b9c7b43...
Total reclaimed space: 2.151GB

This command will clean up the entire system and only keep the images, containers, volumes, and networks that are actually in use, so you need to be extra careful. For example, we cannot run the prune -a command in a production environment because some backup images (for backup, rollback, etc.) are sometimes needed. If these images are deleted, they need to be downloaded again when running the container.

At this point, all images that are not bound to containers will be deleted. Since the first prune command removes all containers, all images (which are not bound to any container) will be removed.

docker systemc info (docker info)

I believe everyone is familiar with the abbreviation of this command docker info

[root@localhost ~]# docker system info
Containers: 6
 Running: 6
 Paused: 0
 Stopped: 0
Images: 49
Server Version: 17.06.2-ce
Storage Driver: overlay
 Backing Filesystem: xfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-514.26.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 24
Total Memory: 31.21 GiB
Name: localhost.localdomain
ID: YTL2:6RWX:IZK6:X4XC:XKMO:WVXD:LXPR:E5GN:GEJB:WIUX:L5YH:PDFB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Registry Mirrors:
 http://9zkjjecg.mirror.aliyuncs.com/
 https://docker.mirrors.ustc.edu.cn/
Live Restore Enabled: false

[root@localhost ~]# 

Detailed explanation

Metacharacters describe
info
Equivalent to docker info
View the information of the entire docker system
For example, docker system info
For example, docker system info | grep Images
events
Equivalent to docker events
Get real-time events of the Docker system, excluding those in containers.
For example: docker system events –until 1499305500
// Operations up to 2017.7.6 01:45:00
For example: docker system events –since 1499305500
// Operations after 2017.7.6 01:45:00
df Overall disk usage
For example: docker system df
For example: docker system df -v
prune Clean up resources. This operation requires special attention.
For example: docker system prune
#Includes cleaning the following four types, namely containers, images, data volumes, and networks
– all stopped containers
– All volumes not used by at least one container
– All networks not used by at least one container
– all dangling images

For example: docker system prune -a
#Including the following four situations, mainly compared with the above
– all stopped containers
– All volumes not used by at least one container
– All networks not used by at least one container
all images without at least one container associated to them

This is the end of this article about the use of the docker system command set. For more relevant docker system content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the problem that vim commands cannot be used in Docker containers
  • Docker compose configuration file writing and command usage examples
  • Basic introduction and use of Docker container image related commands
  • Docker uses the Prune command to clean up the none image
  • Detailed explanation of docker basic commands and usage examples

<<:  An article to understand what is MySQL Index Pushdown (ICP)

>>:  Implementation of Element-ui Layout (Row and Col components)

Recommend

What to do if you forget your Linux/Mac MySQL password

What to do if you forget your Linux/Mac MySQL pas...

The difference between MySQL execute, executeUpdate and executeQuery

The differences among execute, executeUpdate, and...

Vue+flask realizes video synthesis function (drag and drop upload)

Table of contents We have written about drag and ...

Practical experience of implementing nginx to forward requests based on URL

Preface Because this is a distributed file system...

Detailed explanation of the middleman mode of Angular components

Table of contents 1. Middleman Model 2. Examples ...

5 Tips for Protecting Your MySQL Data Warehouse

Aggregating data from various sources allows the ...

An article to teach you HTML

If you are not committed to becoming an artist, t...

Use of Linux network configuration tools

This article introduces RHEL8 network services an...

jQuery implements a simple carousel effect

Hello everyone, today I will share with you the i...

Native js to implement form validation function

Table of contents When developing, analyzing the ...

Rules for registration form design

I finished reading "Patterns for Sign Up &...

A detailed tutorial on how to install Jenkins on Docker for beginners

Jenkins is an open source software project. It is...

A brief discussion on how to write beautiful conditional expressions in JS

Table of contents Multiple conditional statements...