WordPress Docker container slow loading issue in local development WordPress Docker container slow loading issue in local development

How Can I Resolve Slow Page Loading Issues with WordPress Running in Docker?

Improving WordPress Speed in Docker Compose Development

In a local WordPress development environment using Docker Compose, one common issue is slow speed when the volumes (or folders) in the containers are mounted. Even if your computer’s speed is high, you’ll likely still encounter this issue.

Solution One: Bindfs Tool for File Synchronization

An effective solution involves utilizing an open-source software called Bindfs. What this tool does is create a separate temporary folder in the container which will then be mirrored with the public directory in the server.

To put it simply, instead of mounting your project directly to, for example, /var/www/html/ where your WordPress files usually reside, you first mount it to a temporary directory. Later, this folder is synchronized with /var/www/html/ through bindfs.

The advantage of this approach is that every time you load a WordPress page it won’t need to access and read the Host files for every request, which is a heavy process and can slow things down. Instead, the WordPress files become part of the Linux container, making loading them much faster.

When you make changes to your code, they show up in the container’s temporary folder. Bindfs will then instantly sync these changes over to the public folder.

Consequently, any changes made on the public directory will also be mirrored in the temporary directory, and finally, to your Host project files.

You can check out the idea implemented in this WordPress Starter Repository for clarity.

Solution Two: Consistency Option for Volume Performance Issues

Specific to Mac and Windows users, there is an option to handle volume performance issues associated with Docker. By altering the docker-compose.yml file, you can address this.

First, change the short syntax to long syntax in the file. In this context, the syntax refers to how you write or structure the volumes in the docker-compose.yml file.

The long syntax, compared to the short one, allows you to add a consistency option. Consequently, you can now add wp-content and php-conf to the volumes.

These two directories are frequently called every time a WordPress page is loaded in the browser. By adding them and setting consistency: cached, you improve the efficiency of accessing these files.

For concrete implementation, here’s a snippet of the volume configuration in docker-compose.yml:

services:
wordpress:

volumes:
– ./data:/data
– ./scripts:/docker-entrypoint-initwp.d
– type: bind
source: ./wp-content
target: /app/wp-content
consistency: cached
– type: bind
source: ./php-conf
target: /usr/local/etc/php
consistency: cached

Ultimately, the two solutions above can be combined for an overall speed improvement when developing WordPress on Docker Compose. Remember, while these solutions may improve speed and performance, the specific results may depend on your actual setup and individual requirements.