简体   繁体   English

由于docker / cron,设备上没有剩余空间

[英]No space left on device due to docker/cron

I have a basic server on google cloud that just runs a docker container via cron once every 30 minutes. 我在Google云上有一台基本服务器,该服务器每30分钟通过cron运行一次docker容器。 I noticed that the docker command stopped working and I got an error saying 我注意到docker命令停止工作,并且出现错误消息

docker: Error response from daemon: no space left on device.

I then noticed that I got this error even when I trying to autocomplete in bash by typing cd path/ and hitting tab . 然后我注意到即使我尝试通过输入cd path/并点击tab来自动完成bash时也遇到此错误。 I figured out something was probably wrong with the storage so I tried df -h and it showed this: 我发现存储可能出了点问题,所以尝试了df -h并显示了此信息:

Filesystem      Size  Used Avail Use% Mounted on
udev            860M     0  860M   0% /dev
tmpfs           175M   19M  157M  11% /run
/dev/sda1       9.7G  9.7G     0 100% /        
tmpfs           871M     0  871M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           871M     0  871M   0% /sys/fs/cgroup
tmpfs           175M     0  175M   0% /run/user/1001

As you can see /dev/sda1 is 100% full for some reason. 如您所见,由于某些原因,/ dev / sda1已100%充满。 Why is this happening and how can I fix it? 为什么会发生这种情况,我该如何解决?

I noticed there were several thousand exited docker containers so I removed this with this command: 我注意到有数千个退出的Docker容器,因此我使用以下命令删除了它:

docker rm -v $(docker ps -a -q -f status=exited)

Now the storage usage is 61%, which is still too high. 现在存储使用率为61%,仍然太高。

When running containers that you do not need to keep in a stopped state, it's a good practice to use docker run --rm ... to automatically cleanup the stopped container. 在运行不需要保持停止状态的容器时,最好使用docker run --rm ...自动清理停止的容器。

If the container generates volumes, visible in docker volume ls , you'll likely want to clean these once the data is no longer needed. 如果容器生成了在docker volume ls可见的卷,则在不再需要数据后,您可能希望清除这些卷。 with the --rm flag on run, anonymous volumes (which appear as a long unique id) will be automatically deleted. 在运行--rm标志的情况下,匿名卷(显示为长的唯一ID)将被自动删除。

Docker also provides the command: Docker还提供了以下命令:

docker system prune

which you can automate to cleanup images, containers, networks, and even volumes. 您可以自动清理图像,容器,网络甚至卷。 Note that you should take time to understand what this command does before running it, and especially before automating it. 请注意,在运行命令之前,尤其是在自动化之前,您应该花些时间了解此命令的功能。 When scripting this command, you can use the -f flag to bypass the prompt. 在编写此命令脚本时,可以使用-f标志绕过提示。

Before running a prune, you can check: 在运行修剪之前,您可以检查以下内容:

docker system df

to see how much disk is being used by each component, and each component has it's own prune command, eg docker container prune and docker volume prune , should you want to clean just one area. 以查看每个组件正在使用多少磁盘,并且每个组件都有自己的prune命令,例如docker container prunedocker volume prune ,只需要清理一个区域。

For more details on the prune command, see: https://docs.docker.com/engine/reference/commandline/system_prune/ 有关prune命令的更多详细信息,请参阅: https : //docs.docker.com/engine/reference/commandline/system_prune/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM