如何使用docker-compose run查看日志输出? [英] How to view log output using docker-compose run?
问题描述
当我使用 docker-compose up
时,我可以在 docker-compose.yml
中查看所有容器的日志文件。
When I use docker-compose up
I can see logs for all containers in my docker-compose.yml
file.
但是,当我使用 docker-compose run app
时,我只看到<$ c $的控制台输出c> app ,但 app
所不依赖的服务。如何查看其他服务的日志输出?
However, when I use docker-compose run app
I only see console output for app
but none of the services that app
depends on. How can see log output for the other services?
推荐答案
2019年7月1日更新
Update July 1st 2019
docker-compose logs <name-of-service>
来自文档:
用法:日志[options] [SERVICE ...]
Usage: logs [options] [SERVICE...]
选项:
-无彩色产生单色输出。
--no-color Produce monochrome output.
-f,--follow跟随日志输出。
-f, --follow Follow log output.
-t,--timestamps显示时间戳。
-t, --timestamps Show timestamps.
-tail = all每个容器从日志
末尾开始显示的行数。
--tail="all" Number of lines to show from the end of the logs for each container.
查看docker日志
您可以以分离模式启动Docker compose,稍后将自己附加到所有容器的日志中。如果您已看完日志,则可以不关闭日志而将自己从日志输出中分离出来。
See docker logs
You can start Docker compose in detached mode and attach yourself to the logs of all container later. If you're done watching logs you can detach yourself from the logs output without shutting down your services.
- 使用
docker-compose up -d
以分离模式启动所有服务(-d
)(在分离模式下不会看到任何日志) - 使用
docker-compose logs -f -t
来将附加到所有正在运行的服务的日志中,而-f
表示您遵循日志输出和-t
选项为您提供时间戳(请参阅 Docker参考 ) - 使用
Ctrl + z
或Ctrl + c
来 将自己从日志输出中分离而无需关闭运行中的容器
- Use
docker-compose up -d
to start all services in detached mode (-d
) (you won't see any logs in detached mode) - Use
docker-compose logs -f -t
to attach yourself to the logs of all running services, whereas-f
means you follow the log output and the-t
option gives you timestamps (See Docker reference) - Use
Ctrl + z
orCtrl + c
to detach yourself from the log output without shutting down your running containers
如果对单个容器的日志有兴趣的您可以使用 docker
关键字代替:
If you're interested in logs of a single container you can use the docker
keyword instead:
- 使用
docker日志-t -f<服务名称>
- Use
docker logs -t -f <name-of-service>
保存输出
要将输出保存到文件中,请添加以下是您的日志命令:
Save the output
To save the output to a file you add the following to your logs command:
-
docker-compose logs -f -t>> myDockerCompose.log
docker-compose logs -f -t >> myDockerCompose.log
这篇关于如何使用docker-compose run查看日志输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!