Loading…
Warp is now open-source Learn more
Loading…
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>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_zeroAnd this command will output the logs of the container with the ID 7783cbb0deaa:
$ docker logs 7783cbb0deaaTo 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>For example:
$ docker logs -f 5228d692b669If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

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.
In Docker, container logs can be filtered in several ways.
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>For example, the following command shows the latest 80 logs of the container identified by the ID 5228d692b669:
$ docker logs --tail 80 5228d692b669To 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>Or you can use the --until flag to fetch the logs that occurred before a specific:
$ docker logs --until <time> <container_id>Where time is either:
For example, this command will output the logs generated in the last hour:
$ docker logs --since="1h" 5228d692b669And this command will output the logs generated until January 2nd, 2024:
$ docker logs --until="2024-01-02" 5228d692b669To 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>'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'A concise guide to learning Docker using Lazydocker. Highlights Docker’s benefits and takes advantage of Warp's AI features for a quick setup.
Learn how to launch and connect to a containerized SSH server in Docker using password-based authentication and SSH keys.
Learn how to remove a Docker image locally, on a Docker registry, and on Artifactory.
Learn how to override and customize the entrypoint of a Docker container using the docker run command.
Learn how to define and set build-time variables for Docker images using the ARG instruction and the --build-arg flag.
Learn how to start a new Docker container from an image in both the foreground and the background using the docker-run command.
How to gracefully shutdown running containers and forcefully kill unresponsive containers with signals in Docker using the docker-stop and docker-kill commands.
Learn how to set, change and match a docker container hostname.
Learn how define and pass environment variables to Docker containers using an .env file in Docker Compose.
Learn how to write and use .env files in Docker to populate the environment of containers on startup.
Learn how to restart Docker containers automatically with restart policies and manually using the docker restart, docker start, docker stop and docker kill commands.
Start an interactive shell in Docker container
$ docker logs <container_id>$ docker logs container_zero$ docker logs 7783cbb0deaa$ docker logs -f <container_id>$ docker logs -f 5228d692b669$ docker logs --tail <number> <container_id>$ docker logs --tail 80 5228d692b669$ docker logs --since <time> <container_id>$ docker logs --until <time> <container_id>$ docker logs --since="1h" 5228d692b669$ docker logs --until="2024-01-02" 5228d692b669$ docker logs <container_id> | grep '<pattern>'$ docker logs 5228d692b669 | grep 'ERROR'