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

Detailed process of changing apt source to Alibaba Cloud source in Ubuntu 18.04

Table of contents Preface: Ubuntu 18.04 changes a...

How to run Hadoop and create images in Docker

Reinventing the wheel, here we use repackaging to...

Docker custom network container interconnection

Table of contents Preface –link Custom Network As...

Recommended tips for web front-end engineers

Let's first talk about the value of web front...

How to install Nginx in Docker

Install Nginx on Docker Nginx is a high-performan...

Why do code standards require SQL statements not to have too many joins?

Free points Interviewer : Have you ever used Linu...

docker logs - view the implementation of docker container logs

You can view the container logs through the docke...

A brief discussion on docker-compose network settings

Networks usage tutorial Official website docker-c...

Pure CSS3 to create page switching effect example code

The one I wrote before is too complicated, let’s ...

Detailed explanation of the use of DockerHub image repository

Previously, the images we used were all pulled fr...

Installing the ping tool in a container built by Docker

Because the Base images pulled by Docker, such as...

Add crontab scheduled tasks to debian docker container

Now most of the Docker images are based on Debian...

DHTML objects (common properties of various HTML objects)

!DOCTYPE Specifies the Document Type Definition (...

Vue implements multi-tab component

To see the effect directly, a right-click menu ha...