Answers:
首先,我在客户端和服务器上都使用了docker 1.1.2,随着docker的快速发展,这个答案可能对于较新版本的docker来说已经过时了。
找到您的docker目录。在使用apt / debian风格系统的系统上,docker存储库安装的软件包https://get.docker.com/ubuntu
使用/var/lib/docker
。该目录可能在其他系统上的同一位置(无法确认)。
在下面,containers/**CONTAINER_ID**
您会找到有关该容器的信息。在该文件**CONTAINER_ID**-json.log
夹中的文件中,您将找到一个包含该容器的所有日志的文件。它看起来像一个json文件,事实并非如此。这是一个json结构的流,每行一个,每行包含一个日志行(每行以a结尾,}
而下一行以a 开头{
,因此从整体上讲不是有效的json)。
位置示例:- /var/lib/docker/containers/05b6053c41a2130afd6fc3b158bda4e605b6053c41a2130afd6fc3b158bda4e6/05b6053c41a2130afd6fc3b158bda4e605b6053c41a2130afd6fc3b158bda4e6-json.log
我建议您使用该路径查看是否潮湿,这是空间不足的原因,而不是日志轮换它们。
我宁愿确保容器不会记录太多行(通过在dockerfile中使用CMD,将您的处理输出重定向到卷中的文件或/ dev / null-通过配置启用日志-并且然后,我将日志文件与另一个容器进行logrotate)
docker inspect
是你的朋友。
docker inspect --format='{{.LogPath}}' $INSTANCE_ID
docker-machine
这里是一个简单的一线清理容器日志文件:
echo "" > $(docker inspect --format='{{.LogPath}}' <container_name_or_id>)
docker-machine ssh default "echo '' | sudo tee $(docker inspect --format='{{.LogPath}}' <container_name_or_id>)"
docker logs
总是空荡荡的……
docker inspect --format='{{.LogPath}}' <container_name_or_id>
很有用。谢谢!
如果运行sudo lsof | grep '(deleted)'
,则可能会发现有许多已删除的容器日志文件被docker打开
docker 17511 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 2879 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 6191 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 8713 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 8726 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 9907 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 9918 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11093 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11096 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11110 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11885 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11890 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11973 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11976 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 11983 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 13105 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 16737 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17139 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17516 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17517 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17518 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17519 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17520 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17525 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17574 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17584 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17586 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17637 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17643 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17644 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17659 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17666 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17669 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17680 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17884 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 17895 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 21126 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 21474 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 21475 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 21519 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 21721 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 23829 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 23830 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 23833 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 24196 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 24197 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 26821 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 28597 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 28608 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 30305 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 30308 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 30594 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
docker 17511 30595 root 25r REG 202,1 105 456624 /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
这些是属于已删除容器的日志。关闭这些的一种方法是通过重新启动docker守护程序本身。这并不总是可行的。
释放此空间的另一种方法是找到相关的文件描述符并截断它:
ls -lh /proc/17511/fd/ | grep e49d81fc
lr-x------ 1 root root 64 Sep 8 08:06 25 -> /var/lib/docker/containers/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc/39ba30ffc0e218ee830576570222284a93ebb458eadf46933d2dd7afe49d81fc-json.log (deleted)
17511
docker的pid 在哪里,是有e49d81fc
问题的日志文件名/容器ID的一部分。在这里,fd是/ proc / 17511 / fd / 25,因此我们将其截断:
cat /dev/null > /proc/17511/fd/25
: > /proc/17511/fd/25
我正在使用Docker版本1.13.0,内部版本49bf474
如果您使用默认的日志记录格式json-file
,则可以指定选项来轮换日志。
您可以设置docker守护程序来执行此操作,或者针对每个容器进行设置。
例如,日志文件大小为2 MB,最多5个日志文件:
Docker守护程序:创建文件/etc/docker/daemon.json
:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "2m",
"max-file": "5",
}
}
Docker运行:
docker run -it --log-driver json-file --log-opt max-size=2m,max-file=5 alpine ash
要找到码头工人的位置,您可以使用:
docker info
Containers: 16
Images: 45
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Dirs: 78
Execution Driver: native-0.2
Kernel Version: 3.16.0-31-generic
Operating System: Ubuntu 14.10
WARNING: No swap limit support
如果要释放空间,可以采用以下方式:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e2977ed2f4c ekino/puppetlabs:12.04.5 "/bin/bash" 15 hours ago Exited (0) 15 hours ago stoic_jones
ded5903df161 ekino/puppetlabs:12.04.5 "/bin/bash" 12 days ago Exited (0) 11 days ago boring_wilson
72a831b7e4ab a964750d8f91 "/bin/bash" 4 weeks ago Exited (127) 3 weeks ago hungry_meitner
79af8331bad9 a964750d8f91 "/bin/bash" 4 weeks ago Exited (0) 4 weeks ago tender_wilson
d3d3ca34b4b2 1af3728b2912 "/bin/bash" 6 weeks ago Exited (0) 5 weeks ago distracted_shockley
现在,您可以使用以下方法删除容器:
docker rm ac055c58ab19