How to view log output using docker-compose run?

2019-02-02 19:44发布

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?

3条回答
Summer. ? 凉城
2楼-- · 2019-02-02 20:16

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 <container-name>

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
查看更多
Explosion°爆炸
3楼-- · 2019-02-02 20:35

If you want to see output logs from multiple containers. Eg. say you have API container and portal container then you can do something like below :

docker-compose logs -t -f --tail 5 portal api

Where 5 represents last 5 lines from both logs.

查看更多
一纸荒年 Trace。
4楼-- · 2019-02-02 20:42
  1. use the command to start containers in detached mode. : docker-compose up -d
  2. to view the containers : use: docker ps
  3. to view logs for a container :
    docker logs
查看更多
登录 后发表回答