In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "Docker System command analysis", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Docker System command analysis"!
The example is run through play-with-docker.com. Click Add new instance to create a new instance with * version of Docker 17.03 installed. Use the df command to view the initial state of the disk:
$df-h Filesystem Size Used Available Use% Mounted on / dev/mapper/... 10.0G 443.3M 9.6G 4% / tmpfs 60.0G 060.0G 0% / dev tmpfs 60.0G 060.0G 0% / sys/fs/cgroup / dev/xvda1 49.1G 3.7G 43.3G 8% / etc/resolv.conf / dev/xvda1 49.1G 3.7G 43.3G 8% / etc/hostname / dev/xvda1 49.1G 3.7G 43.3G 8% / etc/hosts shm 64.0M 064.0M 0% / dev/shm / dev/mapper/... 10 .0G 443.3M 9.6G 4% / graph/overlay2
You can see that in the newly created play-with-docker.com instance, there is a total 10GB disk space, in which the proximity to 500MB has been occupied.
Next, write Dockerfile to create a mirror. This image is based on the Alpine image; the image will be written to three random files, each file 1GB, generated by the dd command; because this image has no actual effect, CMD is set to / bin/true.
FROM alpine RUN dd if=/dev/zero of=1g1.img bs=1G count=1 RUN dd if=/dev/zero of=1g2.img bs=1G count=1 RUN dd if=/dev/zero of=1g3.img bs=1G count=1 CMD / bin/true
Run docker build-t test. An image can be created, and an image of 3GB will be generated when the execution is completed.
$docker image ls REPOSITORY TAG CREATED SIZE test latest 38 seconds ago 3.23GB alpine latest 5 weeks ago 3.99MB
It is not difficult to understand that the mirror takes up the appropriate amount of disk space.
$df-h Filesystem Size Used Available Use% Mounted on / dev/mapper/... 10.0G 3.4G 6.5G 34% /
If you write only 2 random files, you need to modify the Dockerfile and delete one line. To avoid using caching when building the image, I added a line of echo command before the dd command.
FROM alpine RUN echo foo RUN dd if=/dev/zero of=1g1.img bs=1G count=1 RUN dd if=/dev/zero of=1g2.img bs=1G count=1 # RUN dd if=/dev/zero of=1g3.img bs=1G count=1 CMD / bin/true
I thought this would save 1GB disk space, but the actual situation is even worse!
$df-h Filesystem Size Used Available Use% Mounted on / dev/mapper/... 10.0G 5.4G 4.5G 54% /
The old Docker image exists all the time, and eventually the disk space will be used up quickly. Docker 1.13 introduced the docker system df command, which is similar to the df command on Linux, to view the disk usage of Docker.
$docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 3 0 5.373GB 5.373GB Containers 000B 0B Local Volumes 000B 0B
You can see that there are a total of three Docker images on the instance: the apline image, which contains three 1GB random files and the one containing two 1GB random files. These mirrors take up more than 5GB disk space. Since we are not running containers based on these images, they can all be deleted, so the RECLAIMABLE disk space is 100%. Use docker run test to run the test image and then view:
$docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 3 1 5.373GB 3.225GB (60%) Containers 100B 0B Local Volumes 0.00B 0B
Things are different now. I run a container that exits quickly after / bin/true.
This container is bound with a test image, and the test image is marked as active and cannot be deleted, resulting in less disk space to be recycled.
Now let's clean up the disk space.
Docker provides docker system prune, which can be used to clean up dangling images (see What are Docker: images?) And containers, as well as failed data volumes and networks.
$docker system prune 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 dangling images Are you sure you want to continue [y/N] y Deleted Containers: 1cdf866157b4a97e151125af3c2a7f186a59b6f63807e2014ce1a00d68f44e1d Deleted Images: deleted: sha256:f59bb277... Deleted: sha256:695b8e70... Deleted: sha256:93b1cceb... Deleted: sha256:c74d6bcd... Deleted: sha256:df8b9bb1... Deleted: sha256:dfe8340f... Deleted: sha256:ce1ee654... Total reclaimed space: 3.221GB
According to the warning message, this command removes all closed containers and dangling images. In the example, the name of the image containing three random 1GB files is occupied, and the name is dangling image, so it is deleted. At the same time, all intermediate images will also be deleted. In that case, a total of 3GB disk space is recycled!
Further, use the-an option to do deep cleanup. At this point we will see a more serious WARNING message:
$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 keep only the images, containers, data volumes, and networks that are actually in use, so you need to be very careful. For example, we cannot run the prune-a command in a production environment because some standby images (for backup, rollback, etc.) are sometimes needed, and if these images are deleted, you need to download them again when you run the container.
At this point, all unbound container images will be deleted. Because the * prune command deletes all containers, all images (they are not bound to any containers) will be deleted.
$df-h Filesystem Size Used Available Use% Mounted on / dev/mapper/... 10.0G 442.5m 9.6G 4 / Thank you for reading, the above is the content of "Docker System Command Analysis". After the study of this article, I believe you have a deeper understanding of the problem of Docker System command analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.