Faced a problem, with each build of the project the directory /var/lib/docker/vfs/dir/
constantly growing
How can I clean it?
At the same time docker volume ls
gives nothing
Faced a problem, with each build of the project the directory /var/lib/docker/vfs/dir/
constantly growing
How can I clean it?
At the same time docker volume ls
gives nothing
Why, collecting an image using Dockerfile, do I get a thick layer cake?
This is due to the internal Docker architecture. A docker image is simply a set of layers, each of which is a file system nugget (more precisely, a nugget that is different from the underlying file system) - in fact it is a copy-on-write file system, in which each layer is created by a separate line in Dockerfile. At that moment, when Docker needs to assemble the final file system, it simply collects the composition from these layers, and when the process running in the container needs to get the contents of file X, the assembled file system returns the contents of the file to the top of the layers containing this file; in case you need to write a file, it is written in a new layer (container layer).
This is a key moment in the infrastructure that kills many birds with one stone:
Each of the above layers has its own identifier - the same format as the containers. These are, of course, not very human-friendly, which is why registries (servers with images), repositories (the name of a particular image, for example, ubuntu) and tags (image version, for example 14.04) were invented. All this together (registry-repository tag) can be used to mark a certain layer in a human-friendly style, while the insides remain the same. And when you build a new image with a specific tag, you, de facto, create more layers of the file system, the last of which is marked by the specified tag. Nothing happens with the old layers - they remain in the same place where they were, because the team for creating a new image cannot mean deleting the old ones (since they may still be needed) —from there are leaks of disk space. Under certain conditions (for example, ADD and the http-address of the archive), the instruction, despite its identity, will each time generate a new layer, possibly of considerable volume - this, of course, needs to be monitored and cleaned outdated images. To delete all images without a tag, you can use the following shortcut:
docker rmi $(docker images -qf "dangling=true")
The last thing I want to say is that besides the images, a place can eat and so-called. volume, the cause of which I do not really understand (but, nevertheless, they are and can "hang" inside the host, even when deleting images). They also need to be cleaned from time to time, for this there is a special script .
Thanks for the help! Here is the solution:
docker rmi <image id>
image id can be found by running the command
docker images
It turns out that the RUN command adds a new layer to the existing image, i.e. the 2nd RUN command is encountered in the Dockerfile, the image will be with the 2nd layers and the volume is the first layer + the first layer and minor changes from the 2nd RUN team https://xakep.ru/2015/06/04/docker- faq / Section - Why, collecting an image using a Dockerfile, do I get a thick layer cake?
In docker engine 1.13, you can use docker system prune
. See the documentation .
$ docker system prune WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all build cache Are you sure you want to continue? [y/N]
Source: https://ru.stackoverflow.com/questions/491416/
All Articles
docker ps -a
anddocker images
show? - Sergiksdocker rmi <image id>
- Sergiks