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?
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
to start all services in detached mode (-d
) (you won't see any logs in detached mode)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)Ctrl + z
orCtrl + c
to detach yourself from the log output without shutting down your running containersIf you're interested in logs of a single container you can use the
docker
keyword instead:docker logs -t -f <container-name>
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
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.
docker logs