如何使用 docker-compose run 查看日志输出? [英] How to view log output using docker-compose run?

查看:150
本文介绍了如何使用 docker-compose run 查看日志输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 docker-compose up 时,我可以在我的 docker-compose.yml 文件中看到所有容器的日志.

但是,当我使用 docker-compose run app 时,我只看到 app 的控制台输出,但没有看到 app 依赖的服务.如何查看其他服务的日志输出?

解决方案

在撰写本文时,docker-compose run 命令没有提供查看其他服务日志的开关,因此你需要使用docker-compose logs命令来查看你想要的日志.

2019 年 7 月 1 日更新

docker-compose 日志 <服务名称>

所有服务

docker-compose 日志

使用文档中的以下选项:

<块引用>

用法:记录 [options] [SERVICE...]

<块引用>

选项:

<块引用>

--no-color 产生单色输出.

<块引用>

-f, --follow 关注日志输出.

<块引用>

-t, --timestamps 显示时间戳.

<块引用>

--tail=全部"从日志末尾显示的行数对于每个容器.

查看 docker 日志

您可以在分离模式下启动 Docker compose,稍后将自己附加到所有容器的日志中.如果您已完成查看日志,您可以将自己从日志输出中分离出来无需关闭您的服务.

  1. 使用docker-compose up -d 以分离模式启动所有服务 (-d)(你不会看到任何日志在分离模式下)
  2. 使用docker-compose logs -f -t 将自己附加所有正在运行的服务的日志,而-f 表示您遵循日志输出,-t 选项为您提供时间戳(请参阅 Docker 参考)
  3. 使用 Ctrl + zCtrl + c 将自己从日志输出中分离运行容器

如果您对单个容器的日志感兴趣,可以改用 docker 关键字:

  1. 使用docker logs -t -f


保存输出

要将输出保存到文件中,请将以下内容添加到日志命令中:

  1. docker-compose logs -f -t >>myDockerCompose.log

When I use docker-compose up I can see logs for all containers in my docker-compose.yml file.

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?

解决方案

At the time of writing this the docker-compose run command does not provide a switch to see the logs of other services, hence you need to use the docker-compose logs command to see the logs you want.

Update July 1st 2019

docker-compose logs <name-of-service>

for all services

docker-compose logs

Use the following options from the documentation:

Usage: logs [options] [SERVICE...]

Options:

--no-color Produce monochrome output.

-f, --follow Follow log output.

-t, --timestamps Show timestamps.

--tail="all" Number of lines to show from the end of the logs for each container.

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.

  1. Use docker-compose up -d to start all services in detached mode (-d) (you won't see any logs in detached mode)
  2. 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)
  3. Use Ctrl + z or Ctrl + c to detach yourself from the log output without shutting down your running containers

If you're interested in logs of a single container you can use the docker keyword instead:

  1. 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:

  1. docker-compose logs -f -t >> myDockerCompose.log

这篇关于如何使用 docker-compose run 查看日志输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆