How to see the error logs in WordPress with Docker in Linux
Tags: wordpress, debugging, docker, linux
Published: 2020-01-25 10:58:05

---
title: How to see the error logs in WordPress with Docker in Linux
published: true
date: 2020-01-24 17:47:42 UTC
tags: WordPress,Debugging,Docker,Linux
canonical_url: https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/
cover_image: https://carlosguzman.dev/wp-content/uploads/2020/01/where-are-my-errors-in-wordpress-with-docker-1024x655.jpg
---

Recently I was working in the development of a WordPress plugin and I didn’t find an easy way to see the error logs in WordPress with Docker. I started to read and learn about Docker some few time ago. I created a WordPress development instance using [the official Docker image for WordPress in Docker Hub](https://hub.docker.com/_/wordpress). In some cases, you want to see the log of errors and do not activate the debug mode in WordPress. In example, a plugin can generate warnings that make difficult to debug and that could break responses for Ajax requests in your site.

My first attempt to see the error logs was to login in a bash session it the Docker container. Then I searched for the error log file but the errors are sent to the I/O stream STDERR by default.<mark id="annotation-text-4058d5b7-636c-4a18-bcd5-ab1e309368af"></mark>

![Default configuration of error logs for WordPress with Docker](https://carlosguzman.dev/wp-content/uploads/2020/01/default-error-logs-wordpress-docker.jpg)<figcaption>Default configuration of error logs for WordPress with Docker</figcaption>

Instead to create a custom image to change this configuration, I tried with the [Docker cli tool to access to the logs of the container](https://docs.docker.com/engine/reference/commandline/logs/). Using `docker logs ID_CONTAINER`, I was able to see the logs of the web server. It was progress but it wasn’t what I want. I got all logs entries of the web server including access and warning entries. It would be difficult to spot the error entries easily in a website loading multiple resources and doing multiple Ajax requests.

![Show logs of the Docker WordPress image container.](https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs.jpg)<figcaption>Show logs of the Docker WordPress image container.</figcaption>

## The solution

If we discard the output sent to the standard stream, then the access entries are gone. So using `docker logs -f ID_CONTAINER >/dev/null`, we get only the entries sent to the error stream. Most of the entries here are the useful entries for debugging, they are the warning and error messages. The option -f in docker logs command is to follow and refresh automatically the logs in the console.

![](https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-without-access-entries.jpg)<figcaption>Show entries sent to the error stream only</figcaption>

### Extra tip

If you want to see the error messages only without changing the error reporting directive, you can use the _grep_ tool to filter the other entries. Using `docker logs -f ID_CONTAINER 2>&1 >/dev/null | grep -i error`, the entries are filtered to display only the lines with the error word in them. This command replaces the output of the standard stream with the output of the error stream. Then _grep_ filters the content. The option -i in the _grep_ command is to be case insensitive in the search.

![Show only error logs of WordPress with Docker](https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-only-errors.jpg)<figcaption>Show only error logs of WordPress with Docker</figcaption>

Maybe it isn’t the most elegant but at least it is an effective way to see the error logs in WordPress with Docker.

The post [How to see the error logs in WordPress with Docker in Linux](https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/) appeared first on [Carlos Guzman](https://carlosguzman.dev).