Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Check and Manage Logs in Docker Compose

Set up a small Compose project, then read, follow, filter and save its logs.

VPS and Cloud Servers2 min read5 steps13 screenshots

What Compose logs are

Docker Compose logs are the combined output (stdout and stderr) of all services in your docker-compose.yml. They help you watch what your containers do and find errors.

Install Docker Compose on Ubuntu

sudo apt install docker-compose

Or install Docker and its plugins:

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Check the installation:

docker compose version
Docker Compose version

Create a test project

  1. Create the folders and a page:
mkdir ~/compose-demo
cd ~/compose-demo
mkdir app
nano app/index.html
Creating the project folder
  1. Put this in index.html:
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Docker Compose Demo</title>
</head>
<body>
    <h1>This is a Docker Compose Demo Page.</h1>
</body>
</html>
The demo page
  1. Create the file docker-compose.yml in ~/compose-demo:
services:
  web:
    image: nginx:alpine
    ports:
      - "8000:80"
    volumes:
      - ./app:/usr/share/nginx/html
The docker-compose.yml file
  1. Start the project in the background:
sudo docker compose up -d
Starting the services
  1. Check that it runs:
sudo docker compose ps
Running containers

Read the logs

All services:

sudo docker compose logs
Logs of all services

One service:

sudo docker compose logs web
Logs of the web service

Follow in real time (press Ctrl + C to stop):

sudo docker compose logs -f
Live logs

Only the last lines:

sudo docker compose logs --tail=10
The last 10 lines

Add time stamps:

sudo docker compose logs -t

Filter the output with grep:

sudo docker compose logs | grep error
Filtered logs

Save the logs to a file:

sudo docker compose logs > logs.txt
Logs saved to a file

Clean up

Stop and remove the test project:

sudo docker compose down
Stopping the project
Tip: Logs can grow big. In the service definition, set a log limit, for example logging: { driver: json-file, options: { max-size: "10m", max-file: "3" } }.

Quick recap

  • docker compose logs shows all logs, add a service name for one service.
  • -f follows, --tail limits, -t adds time.
  • Pipe to grep or save to a file.