LinuxCommandLibrary

docker-compose-logs

View Docker Compose service logs

TLDR

View logs for all services

$ docker compose logs
copy

View logs for a specific service
$ docker compose logs [service_name]
copy

View logs and follow new output (like tail --follow)
$ docker compose logs [[-f|--follow]]
copy

View logs with timestamps
$ docker compose logs [[-t|--timestamps]]
copy

View only the last n lines of logs for each container
$ docker compose logs [[-n|--tail]] [n]
copy

View logs from a specific time onwards
$ docker compose logs --since [timestamp]
copy

View logs until a specific time
$ docker compose logs --until [timestamp]
copy

View logs for multiple specific services
$ docker compose logs [service1 service2 ...]
copy

SYNOPSIS

docker-compose logs [OPTIONS] [SERVICE...]

PARAMETERS

-f, --follow
    Follow log output continuously

--no-log-prefix
    Omit log lines prefixed with service name

--since SINCE
    Show logs since timestamp (e.g., '2023-01-01T00:00' or '5m')

--tail NUMBER
    Show NUMBER lines from end (default 'all')

-t, --timestamps
    Show timestamps on each log line

--until UNTIL
    Show logs before timestamp (e.g., '2023-01-01T00:00' or '5m')

-h, --help
    Display help for the command

DESCRIPTION

The docker-compose logs command fetches and displays log output from running services defined in a docker-compose.yml file. It aggregates logs from multiple containers associated with specified services, prefixing each line with the service name and container ID for easy identification.

By default, it shows all available logs from the start of each service. This is invaluable for debugging applications orchestrated with Docker Compose, allowing real-time monitoring or historical review. Options enable filtering by time (--since, --until), limiting output (--tail), adding timestamps (--timestamps), or continuous streaming (--follow).

When no services are specified, logs from all services are displayed. Output is color-coded if the terminal supports it, aiding in distinguishing between services. Logs are read from Docker's logging drivers, respecting configured log drivers like json-file or syslog. This command does not alter container state and is safe for production use.

CAVEATS

Logs respect Docker daemon's log rotation and driver settings; may be incomplete if rotated or pruned. Not suitable for very high-volume logs without --tail. Requires services to be running or have recent logs.

EXAMPLES

docker-compose logs web
Show logs for 'web' service.

docker-compose logs -f --tail=100
Follow recent 100 lines from all services.

EXIT CODES

0 on success; 1 on error (e.g., no services found, invalid options).

HISTORY

Introduced with Docker Compose v1.0 in 2013 as part of multi-container orchestration tools. Evolved with Docker Compose v2 (2021) integrating into docker compose subcommand, maintaining backward compatibility.

SEE ALSO

docker-compose ps(1), docker logs(1), docker-compose up(1), journalctl(1)

Copied to clipboard