如何使用 docker 日志
How to use docker logs
这个问题可能有点新手。
我 运行 docker exec -it mycontainer bash
进入守护进程容器(postgresSQL),
和 echo
东西。
现在我退出它,并使用 docker logs mycontainer
以查看我的回声。
根据
The docker logs command batch-retrieves logs present at the time of execution.
The docker logs --follow command will continue streaming the new output from the container's STDOUT and STDERR.
容器的docker logs
listenSTDOUT
,为什么我看不到我的字符串只是echoed在里面?
I 假设 日志记录仅针对容器中的主进程发生。当 exec 创建一个新进程时,它不会被记录。
请注意,docker logs
适用于 运行 命令中给出的进程,例如:
$ ID=$(docker run -d debian sh -c "while true; do echo "hello"; sleep 1; done;")
$ docker logs $ID
hello
hello
hello
hello
hello
Docker 引擎仅存储 ID 为 0 的进程的标准输出(即由 Docker 文件的 CMD 指令启动的进程)。
顺便说一下,在您的 Docker 主机上,您可以通过查看文件 /var/lib/docker/containers/<ID of your container>/<ID of your container>-json.log
.
来检查容器日志的内容
此文件以 JSON 格式存储日志。
这个问题可能有点新手。
我 运行 docker exec -it mycontainer bash
进入守护进程容器(postgresSQL),
和 echo
东西。
现在我退出它,并使用 docker logs mycontainer
以查看我的回声。
根据
The docker logs command batch-retrieves logs present at the time of execution. The docker logs --follow command will continue streaming the new output from the container's STDOUT and STDERR.
容器的docker logs
listenSTDOUT
,为什么我看不到我的字符串只是echoed在里面?
I 假设 日志记录仅针对容器中的主进程发生。当 exec 创建一个新进程时,它不会被记录。
请注意,docker logs
适用于 运行 命令中给出的进程,例如:
$ ID=$(docker run -d debian sh -c "while true; do echo "hello"; sleep 1; done;")
$ docker logs $ID
hello
hello
hello
hello
hello
Docker 引擎仅存储 ID 为 0 的进程的标准输出(即由 Docker 文件的 CMD 指令启动的进程)。
顺便说一下,在您的 Docker 主机上,您可以通过查看文件 /var/lib/docker/containers/<ID of your container>/<ID of your container>-json.log
.
此文件以 JSON 格式存储日志。