• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Tail Container Logs In Docker

Nitish Singh

Published: 1/26/2024

About Terminus

The short answer

In Docker, retrieving the logs of containers during their execution allows to simplify the debugging and tracing issues for developers.

To output the logs of a specific Docker container, you can use the docker logs command as follows:

 $ docker logs <container_id>

Run in Warp

Where container_id is either the name or the identifier of the container, which can be obtained using the docker ps command.

For example, this command will output the logs of the container named container_zero:

 $ docker logs container_zero

Run in Warp

And this command will output the logs of the container with the ID 7783cbb0deaa:

 $ docker logs 7783cbb0deaa

Run in Warp

Displaying container logs in real-time

To monitor the logs of a docker container in real-time, you can use the docker logs command with the -f flag (short for --follow):

 $ docker logs -f <container_id>

Run in Warp

For example:

 $ docker logs -f 5228d692b669

Run in Warp

Easily retrieve this command using Warp’s AI Command Suggestions

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Thumbnail for

Entering docker logs real-time in the AI Command Suggestions will prompt a docker command that can then quickly be inserted into your shell by doing CMD+ENTER.

Filtering container logs

In Docker, container logs can be filtered in several ways.

Outputting the last N logs

To show the latest log entries, you can use the --tail option, followed by the number of logs to display:

 $ docker logs --tail <number> <container_id>

Run in Warp

For example, the following command shows the latest 80 logs of the container identified by the ID 5228d692b669:

 $ docker logs --tail 80 5228d692b669

Run in Warp

Filtering logs by date and time

To filter container logs based on timeframes, you can either use the --since flag to fetch the logs that occurred after a specific time:

 $ docker logs --since <time> <container_id>

Run in Warp

Or you can use the --until flag to fetch the logs that occurred before a specific:

 $ docker logs --until <time> <container_id>

Run in Warp

Where time is either:

  • A timestamp expressed in the following format: YYYY-MM-DDTHH:MM:SS.NNNNNNZ.
  • A relative duration expressed in the following format: <number>[h|m|s] where h, m, s stand for hours, minutes, and seconds.

For example, this command will output the logs generated in the last hour:

 $ docker logs --since="1h" 5228d692b669

Run in Warp

And this command will output the logs generated until January 2nd, 2024:

 $ docker logs --until="2024-01-02"  5228d692b669

Run in Warp

Filtering logs based on patterns using the grep command

To filter the container logs based on specific keywords or patterns, you can pipe the output of the docker logs command into the grep command:

 $ docker logs <container_id> | grep '<pattern>'

Run in Warp

For instance, if the container is throwing an error, you can find out more about it by searching for the ERROR keyword:

 $ docker logs 5228d692b669 | grep 'ERROR'

Run in Warp

Written by

Nitish Singh

Filed Under

Related Articles

Override the Container Entrypoint With docker run

Learn how to override and customize the entrypoint of a Docker container using the docker run command.

Docker

The Dockerfile ARG Instruction

Learn how to define and set build-time variables for Docker images using the ARG instruction and the --build-arg flag.

Docker
Thumbnail for Razvan LudosanuRazvan Ludosanu

Start a Docker Container

Learn how to start a new Docker container from an image in both the foreground and the background using the docker-run command.

Docker
Thumbnail for Razvan LudosanuRazvan Ludosanu

Stop All Docker Containers

How to gracefully shutdown running containers and forcefully kill unresponsive containers with signals in Docker using the docker-stop and docker-kill commands.

Docker
Thumbnail for Razvan LudosanuRazvan Ludosanu

Use An .env File In Docker

Learn how to write and use .env files in Docker to populate the environment of containers on startup.

Docker

Run SSH In Docker

Learn how to launch and connect to a containerized SSH server in Docker using password-based authentication and SSH keys.

Docker
Thumbnail for Gabriel ManricksGabriel Manricks

Launch MySQL Using Docker Compose

Learn how to launch a MySQL container in Docker Compose.

DockerSQL

Execute in a Docker Container

Learn how to execute one or multiple commands in a Docker container using the docker exec command.

Docker
Thumbnail for Razvan LudosanuRazvan Ludosanu

Expose Docker Container Ports

Learn how to publish and expose Docker container ports using the docker run command and Dockerfiles.

Docker

Restart Containers In Docker Compose

Learn how to restart and rebuild one or more containers in Docker Compose.

Docker
Thumbnail for Razvan LudosanuRazvan Ludosanu

Output Logs in Docker Compose

Learn how to output, monitor, customize and filter the logs of the containers related to one or more services in Docker Compose

Docker
Thumbnail for Razvan LudosanuRazvan Ludosanu

Rename A Docker Image

Learn how to rename Docker images locally and remotely using the docker tag command.

Docker

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Thumbnail for null