docker cleanup scheme

In the process of using docker, we found that the Storage Driver: overlay is used for storage based on swarm. But we found that this takes up storage space in particular.

clean up all stopped containers

docker container prune

Clean up all unused data (stopped containers, unused volumes, unused networks, dangling images)

docker system prune -a

overlay storage

We have cleared some useless data through the above operations, but the overlay is still very large. Let's first understand the overlay storage.

overlayfs

It is integrated into the linux 3.18 kernel.
The overlay storage driver mainly uses overlayfs technology. The Chinese name is overlay file system. Multiple file systems can be combined after mounting.
docker image layer lowerdir
docker container layer upperdir
docker container mount point merged

These three layers correspond to the structure of overlayFs. We can see the following structure through docker inspect

"GraphDriver": {
            "Name": "overlay",
            "Data": {
                "LowerDir": "/mnt/docker/overlay/5eb97eb91bed89a9c879142900419ad118215af05c291989282c130d031d7019/root",
                "MergedDir": "/mnt/docker/overlay/454f70c61de03ce2a517d7e2ea8c19e319a95cd2275d8b826f4244071315e513/merged",
                "UpperDir": "/mnt/docker/overlay/454f70c61de03ce2a517d7e2ea8c19e319a95cd2275d8b826f4244071315e513/upper",
                "WorkDir": "/mnt/docker/overlay/454f70c61de03ce2a517d7e2ea8c19e319a95cd2275d8b826f4244071315e513/work"
            }
        }

Mirror at /root
mount point at /merged
container at /upper
working directory/work

overlayfs data cleanup

We did an experiment, we started a container (different version), after

docker stop conatiner
docker rm container

By monitoring the data size, we found that the overlay will generate some data as new images are generated. As the container is closed and deleted, the file does not shrink in size. How to solve it? It seems that we have overlooked a problem. We use docker system pruneI thought that all unnecessary data could be cleaned up, but about the "dangling images" dangling image described in images. I don't understand this term yet. But through the test, even if I stop the container, the image cannot be cleaned up, so, I can't understand what the state of suspension is.

docker rmi images

Finally, by manually deleting the mirror, the previously generated overlay data is reduced.

Tips:
Check the overlay size du --max-depth=1 -h
Check the quantityls|wc -w

tidy

If there is a new version of the image, we can follow this process

docker stop container
docker rm container
docker rmi image
docker pull image
docker run ...

This prevents the system disk from filling up in the blink of an eye.

other

docker time synchronization?

ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone

docker storage location modification

ExecStart=/usr/bin/dockerd --graph="/mnt/data/images"



http://www.jianshu.com/p/6ca10427ad77

https://segmentfault.com/a/1190000009175004

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326246272&siteId=291194637