docker 信息:
Containers: 18
Running: 18
Paused: 0
Stopped: 0
Images: 188
Server Version: 1.13.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1
runc version: 9df8b306d01f59d3a8029be411de015b7304dd8f
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.0-1-amd64
Operating System: Debian GNU/Linux 9 (stretch)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.56 GiB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Docker version 1.13.1, build 092cba372
FROM debian:latest
RUN touch /var/log/mylog.log
CMD ["tail", "-F", "/var/log/mylog.log"]
docker build . -t test/test
构建它并使用 docker run -ti test/test
运行它将像这样在标准输出中拖尾文件(忽略尾部警告):$ docker run --name test -t test/test
tail: unrecognized file system type 0x794c7630 for '/var/log/mylog.log'. please report this to [email protected]. reverting to polling
/var/log/mylog.log
这是一个文件,后面跟着 tail
:docker exec -ti test bash -c "echo 'asd' >> /var/log/mylog.log"
cat
,另一个终端也没有输出显示文件中有内容:$ docker exec -ti test bash -c "cat /var/log/mylog.log"
asd
docker stop test && docker start test
,我也可以获得尾部的内容使用较早的命令。使用 overlay2
的我也遇到了同样的问题Docker 上的存储驱动程序 4.9.8-moby
Alpine 释放。
好像CMD tail
正在开通/var/log/mylog.log
来自覆盖层的文件 RUN touch /var/log/mylog.log
创造。
当您附加到日志时,会在最顶层的覆盖层中创建一个"new"文件,容器用于在运行时对镜像顶部进行的任何文件系统更改,并且这个新文件实际上是附加到的。 tail
但是,无论是使用 -f
还是无法正确进行转换或 -F
.docker start
和 docker stop
将问题解决为 tail
进程在 /var/log/mylog.log
之后再次启动已更新,然后指向容器覆盖层中的"new"文件。使用略有不同的 CMD
将以类似的方式解决该问题:
CMD ["sh", "-c", "touch /var/log/mylog.log && tail -f /var/log/mylog.log"]
debian:testing
图像包括 coreutils-8.26-2 与支持覆盖魔数(Magic Number)的修复程序,以删除该警告消息,但仍表现出相同的行为。-F
时,coreutils 或许能够解决这个问题。 .tail
的容器因为前台进程通常在运行之前在脚本中完成一堆工作tail
,其中包括运行创建要跟踪的日志文件的命令。这可能就是为什么没有多少人选择这个的原因。
关于docker - 为什么我无法获得由 docker build 创建的文件尾部的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42614853/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |