docker运行中容器不释放磁盘空间
PHP中文网
PHP中文网 2017-04-24 09:12:58
0
1
1208

大家好,想咨询一下,docker是如何管理磁盘的呢?我有个jenkins的应用放在了一个容器里面,运行一段时间后容器变得非常巨大,然后我在容器中删除了部分大的文件,df -h发现不管是容器的虚拟分区还是宿主机的磁盘都没有释放任何空间出来,依旧是42%(容器)和50%(宿主)的磁盘占用,这是什么原因造成的呢?该如何解决呢?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
大家讲道理

You need to understand Dockerimages and containers. Of course, this is understood from the perspective of the file system.

Docker images are read-only files. To emphasize, it is read-only, so we cannot actually delete the files in the image. When you delete it, you just make a mark so that the container cannot see the file. So this file still exists in the image and takes up disk space.

Docker container is a read-write layer based on the image, which is readable and writable. When reading and writing a file, the file is copied from the image to the read-write layer of the container, and then the copied file is read and written, while the original file is still in the image. Moreover, the read-write layer of this container also takes up disk space.

So, we can only free up disk space by deleting images and containers.

Delete image

sudo docker rmi <Image Name>

Delete container

sudo docker rm <Container Name>

Delete all images

sudo docker rmi -a

Delete all containers

sudo docker rm -a

In addition, the container’s data volume also takes up disk space. You can delete the expired volume through the following command:

sudo docker volume rm $(docker volume ls -qf dangling=true)

Of course, the most violent way is to delete the directory where Docker stores images, containers and data volumes (/var/lib/docker)

Use with caution! ! ! :

sudo service docker stop
sudo rm -rf /var/lib/docker
sudo service docker start
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template