View logs for a specific Docker Compose service
When using docker-compose up, we can see the logs of all containers in the YAML file; however, if we specify a specific container service, the output will not show any service dependencies in the log. Therefore, this article will explore how to correctly export the output Docker Compose service logs.
View logs for a specific Docker Compose service
You can start Docker Compose in detached mode and later attach yourself to the logs of all containers. Then, if you are done watching the log traces, you can detach from the log output without shutting down the service.
Follow these steps to accomplish this:
-
Use
docker-compose up -d
-d option to start all services in detached mode. -
Use
docker-compose logs -t -f
to attach ourselves to the logs of all running services. The -t option gives us a timestamp, and the -f parameter means we follow the log output while the service is running. - Use Ctrl+Z or Ctrl+C to detach yourself from the log output without shutting down the running container.
-
If we need to specify the logs of a single container, we can use the following command:
$ docker-compose logs -t -f <service name>
-
To save the output to a file, we can
>>
add it to the end of the command using the - operator.$ docker-compose logs -t -f >> sample.log
Using Docker Compose V2
Starting with Docker Compose version 2, we can now use docker-compose without the dash (-). We can also use most of the docker-compose commands and call them similarly without the dash:
$ docker compose logs -t -f --tail 3 sample-service test-service >> sample.log
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Differences between Docker and Docker Compose
Publish Date:2025/03/24 Views:146 Category:Docker
-
Both docker and docker compose docker run Docker containers. The two Docker constructs are comparable, but that's about it. This article will discuss docker compose the main differences between docker and . Differences between Docker and Do
Recreate the container from the new image using Docker-Compose
Publish Date:2025/03/24 Views:178 Category:Docker
-
As we develop our applications, we often make changes or add more features to make the application more effective for the different users who interact with the application. When using Docker, we need to ensure that the changes or features w
Exposing multiple ports in a Docker container
Publish Date:2025/03/24 Views:186 Category:Docker
-
There are different types of communication on the Internet, the most common ones include file transfers, sending emails, and serving web pages. To make this communication possible, we make use of port numbers that help identify the type of
Using Docker network host commands
Publish Date:2025/03/24 Views:51 Category:Docker
-
Docker containers work by leveraging network drivers that are created during the installation of Docker. The default drivers available to us include bridge and host networking. When we create containers without specifying a network, they ar
Clear Docker container logs
Publish Date:2025/03/24 Views:192 Category:Docker
-
Logs are information recorded by the application when a specific event or state occurs. They help us monitor the application and take necessary actions. For example, when we deploy an application to a production environment, logs can help u
Docker daemon log location
Publish Date:2025/03/24 Views:65 Category:Docker
-
The Docker daemon provides essential information about the general state of your microservices architecture. Unfortunately, container-centric logging techniques allow you to collect relevant data from your services but provide little inform
Difference between COPY and ADD commands in Dockerfile
Publish Date:2025/03/24 Views:140 Category:Docker
-
A Dockerfile is a text document that contains all the commands used to build a Docker image. Recently, we have seen Docker being widely used as the default tool for managing configurations and automating deployments. Advanced features such
The --rm flag in Docker
Publish Date:2025/03/24 Views:151 Category:Docker
-
Typically, when most developers start using docker, after going through all the processes of pulling images, building them, and running containers, removing a container defeats the purpose of doing so. However, for experienced developers, t
Setting environment variables in Docker
Publish Date:2025/03/24 Views:188 Category:Docker
-
Environment variables are used to add additional configuration or metadata to aid in the development of an application, and can exist in different forms. For example, when developing a Java application, we usually set an environment variabl