Docker: Container Logs – How to Check

The docker logs command serves for accessing the logs of a container.

In this post i am showing how to check the logs of a Docker container, see the timestamps and how to tail or grep these logs.

I will also show how to find out where the Docker container logs are stored.

Cool Tip: Clean up a Docker host! Remove unused Docker containers! Read More →

Use the docker ps command to list running containers and find out the name or ID of a container which logs you would like to check:

$ docker ps
CONTAINER ID  IMAGE    COMMAND  CREATED      STATUS      PORTS  NAMES
72ca2488b353  my_image          X hours ago  Up X hours         my_container

Check Docker Container Logs

Check the logs of a Docker container:

$ docker logs container

Show the Docker container logs with timestamps:

$ docker logs container --timestamps

Show Docker logs since particular date:

$ docker logs container --since YYYY-MM-DD

Show Docker logs since particular time:

$ docker logs container --since YYYY-MM-DDTHH:MM

e.g. check Docker logs since 11 am:

$ docker logs container --since 2018-01-30T11:00

Cool Tip: Enter a running Docker container and start a bash session! Read More →

Tail Docker Logs

It is possible to show only the latest Docker logs as well as continuously follow the Docker container logs in the real time.

tail the last N lines of logs:

$ docker logs container --tail N

tail -f (follow) the Docker container logs:

$ docker logs container --follow

Grep Docker Logs

grep Docker container logs:

$ docker logs container | grep pattern

e.g. show the error logs only:

$ docker logs container | grep -i error

Cool Tip: Copy files between Docker container and a host machine! Read More →

Docker Container Logs Location

Find out where the Docker container logs are stored:

$ docker inspect --format='{{.LogPath}}' container
Was it useful? Share this post with the world!

Leave a Reply