大网数据广告活动
服务器运维问答

Out of space on EC2 instance due to docker logs

· 52CE 我爱测

I'm still learning docker and AWS, and I've had a docker process running awhile with 50gb EBS storage, and now I'm out of disk space and as a result, docker no longer starts up when I reboot my instance. When I try sudo du -h / |…

问题原文

原帖链接 · user1956609 · CC BY-SA 3.0

I'm still learning docker and AWS, and I've had a docker process running awhile with 50gb EBS storage, and now I'm out of disk space and as a result, docker no longer starts up when I reboot my instance.

When I try sudo du -h / | grep '[0-9\.]\+G' I get:

1.8G    /var/lib/docker/containers/f7cf0...
17G     /var/lib/docker/containers/55b7e...
2.8G    /var/lib/docker/containers/987b0...
22G     /var/lib/docker/containers/726b0...
44G     /var/lib/docker/containers
4.3G    /var/lib/docker/devicemapper/devicemapper
4.3G    /var/lib/docker/devicemapper
48G     /var/lib/docker
48G     /var/lib
48G     /var
0       /sys/bus/mdio_bus/drivers/Generic 10G PHY
50G     /

And when I try sudo docker ps -a I get:

Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

I don't want to touch the 726b0... process, that's the most important. Will it cause problems if I delete the .log file for 55b7e...? Is there a cleaner way to do that than to just remove the file?

社区高分解答

原帖链接 · Elad Nava · CC BY-SA 4.0

If you're using Elastic Beanstalk to run Docker, this may interest you.

I took Yonatan's command and converted it into an .ebextensions cron job that will run every X hours, and clear the Docker container logs so that they don't accumulate and clog the server. I had to modify it to use tee to avoid an ambiguous redirect bash error.

Simply create an .ebextensions directory in your repository root (next to Dockerrun.aws.json) and a docker-log-truncate.config file inside it with the following content:

commands:
    add_docker_log_truncate_cronjob:
        command: "crontab -l | grep -q 'eb-docker' || (crontab -l ; echo '0 * */6 * * /bin/echo 0 | tee /var/log/eb-docker/containers/*/*.log')| crontab -"
        ignoreErrors: true

In this case, the command will run every 6 days and clear your Docker container logs. Note that I was not able to update my Elastic Beanstalk with this change until I terminated all affected servers, probably because Beanstalk needs some free disk space to deploy the new version.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-05-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。