Docker Community Forums

Share and learn in the Docker community.

How to access the Docker log file from WITHIN the container?

How can I access the Docker log file from INSIDE the container? Why do I need this? Because I am running Wordpress in a Docker container and want to direct debug messages to the Docker log instead of the wp-content/error.log file. Refer:

So I need the path of the Docker log file that I can then enter in:

define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );

This link:

seems to suggest this is not possible. Is that really so? How do applications then write to Docker log in the first place?

Debugging Docker Issues with Container Logs
Docker has a dedicated API for working with logs. But, keep in mind, it will only work if you use the json-file log driver. I strongly recommend not changing the log driver! Let’s start debugging.

First of all, to list all running containers, use the docker ps command.

docker ps
Then, with the docker logs command you can list the logs for a particular container.

docker logs <container_id>
Most of the time you’ll end up tailing these logs in real time, or checking the last few logs lines.

Using the --follow or -f flag will tail -f (follow) the Docker container logs:

docker logs <container_id> -f
The --tail flag will show the last number of log lines you specify:

docker logs <container_id> --tail N
The -t or --timestamp flag will show the timestamps of the log lines:

docker logs <container_id> -t
The --details flag will show extra details about the log lines:

docker logs <container_id> --details
But what if you only want to see specific logs? Luckily, grep works with Docker logs as well.

docker logs <container_id> | grep pattern
This command will only show errors:

docker logs <container_id> | grep -i error
Once an application starts growing, you tend to start using Docker Compose. Don’t worry, it has a logs command as well.

docker-compose logs
This will display the logs from all services in the application defined in the Docker Compose configuration file.

Find ID of the necessary container via - docker ps
Get inside your container via - docker exec -it YourContainerIdHere sh
Find necessary process via - ps aux
Execute - cat /proc/<PIDofYourProcess>/fd/1