Docker容器持续增长 [英] Docker container keeps growing
问题描述
我有一个循环播放的pyhton脚本
I have a pyhton script that on a loop
- 将视频块从AWS S3下载到/filename
- 按顺序排列文件并将其合并.
- 将整个处理后的视频文件上传到AWS S3
- 删除文件夹/filename
然后继续循环,直到AWS SQS队列为空.
Then continues on a loop until the AWS SQS queue is empty.
脚本效果很好!我已经运行了几个月.硬盘空间各不相同,但从不超过5%,具体取决于视频的大小.
Scripts works great! I have run it for months. The hard drive space varies but never gets about 5%, depending on size of the video.
我决定将此脚本放入docker容器中并运行docker-compose,以便我可以一次运行一堆.
I decided to put this script in a docker container and run docker-compose so I could run a bunch of them at a time.
问题是硬盘驱动器已满!我知道运行5会占用磁盘上的空间,但是当我处理完文件后,就删除它.
The problem is the hard drive fills up! I know with 5 running the space on the disk will be hire, but when I'm done processing the file get delete.
但是对于docker,似乎是缓存或其他东西.我执行每个容器,它们运行良好.删除所有旧文件.
But with docker, seems to be a cache or something. I exec into each container and they are running fine. Delete old files and all.
不知道在Docker容器中和作为服务运行之间的区别会对HD产生影响.
No clue what the difference between in a docker container and running as a service would have the impact on the HD.
任何方向都很好.
要添加到此.当我"rm" docker容器时,硬盘驱动器空间将释放.我运行了一个docker ps -s,容器上的空间并不疯狂.就像当您在docker容器中"rm"一个文件时,它从未真正rm过.
To add to this. When I "rm" the docker containers the hard drive space frees up. I run a docker ps -s and the space on the containers is not crazy. Just seems like when you "rm" a file inside the docker container it never really rm it.
推荐答案
如果您将映像下载到主机未映射的目录中,则Docker容器在删除容器之前不会释放使用的磁盘空间- -容器中所做的任何事情都是短暂的,但是HOST并不知道容器中正在发生的事情的状态.
If you're downloading the image to a directory NOT volumed mapped from the host, the docker container will not release the used disk space until the container is removed--anything done in the container is ephemeral, but the HOST doesn't know the state of what's going on inside the container.
从这个意义上讲,它很像一个虚拟机映像,由一个文件支持,该文件只会根据需要增长,而不会缩小. Docker有一个用于运行容器跟踪更改的目录.在主机上,您可以在/var/lib/docker/containers/<id>
In this sense it's a lot like a virtual machine image, backed by a file that just grows as needed, but never shrinks. Docker has a directory for a running container tracking changes. On the host you can find the files backing the running container in /var/lib/docker/containers/<id>
如果您需要容器共享磁盘空间,建议您将主机中的共享卷映射到每个docker容器映像中进行共享.
If you need your containers to share disk space, I'd recommend you map a shared volume from the host into each docker container images to share.
尝试以下
docker run -ti -v /host/dir:/container/dir ubuntu bash
以上内容将以终端交互模式运行ubuntu映像,并将主机的目录/host/dir
安装在正在运行的容器中.容器写入/container/dir
的任何内容都将出现在主机/host/dir
中,安装它的任何其他容器也将看到更改.
The above would run the ubuntu image in terminal interactive mode and mounting the host's directory /host/dir
inside the running container. Anything the container writes to /container/dir
will appear in the hosts /host/dir
and any other containers mounting it will see the changes as well.
请记住,共享卷上的所有容器都可以看到共享卷中完成的所有操作,因此在添加和删除文件/目录时要小心!
Just remember anything done in the shared volume is seen by all containers that mount it, so be careful when adding and deleting files/directories from it!
这篇关于Docker容器持续增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!