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 June 10th 2022
As commented by @Sandburg docker compose is now integrated into docker. As described here most of the docker compose commands can be called the same way just without the hyphen. So docker compose instead of docker-compose:
The new Compose V2, which supports the compose command as part of the Docker CLI, is now available.
Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
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.
- 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
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:
- 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 service_name
docker-compose run
creates new container each time you execute it.docker-compose run
in circleci just to run my tests so its okay if it creates a new container. The main issue is just not seeing log output from the dependent services.