Docker Wordpress super slow

I have been experiencing the same issue but might have found a solution.

In the docker Desktop app (up top with the time, looks like a whale)

Open Settings Select Resources\File Sharing

Add the relevant folders. I had MySQL and the Wordpress folders in the same parent folder so added that.

Click Apply and Restart.

My website sped up massively.

I hope this helps.


In Mac and Windows there are some volumes performance issues that we should consider.

I made change in my docker-compose.yml

Note as I changed the short syntax to long syntax.

This notation permits add consistency option.

I added wp-content and php-conf (to get php.ini) because they are files directory most frequently called every time when a Wordpress page is loaded in browser.

services:
    wordpress:

        ...

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

enter image description here


I realized that if you narrow the directories that Docker has to look through to run your site, it'll run much faster. For example, in Docker Desktop Settings, /Users is default in Settings > Resources > File Sharing. If you delete that resource and just narrow it down to the directory your site(s) are in, that'll get rid of a lot of overhead for Docker.

enter image description here


TL;DR Mount to temporary folder on container, sync that folder with Bindfs to public server folder. Serving WP site with direct mount is slow because container has to access Host files one by one, which is a heavy process. Serving from public folder while files being part directly of container is much faster.

I've encountered exactly the same problem with local WordPress on Docker Compose development. It doesn't matter how fast your computer might be, it'll still be slow when mounting the folders in the containers.

I also tried solutions like NFS and other recommendations like properly excluding the project in the antivirus, adding .dockerignore, etc. which at best improve just slightly the performance.

While browsing for a similar speed improvement I came across this Dockerfile at the WordPress Starter repository https://github.com/visiblevc/wordpress-starter/blob/master/Dockerfile. If you look at this file you'll see that the way they intialize and mount the project in the container is by mounting it not to, let's say, /var/www/html/ directly, but a temporary folder instead. Then they sync this temporary folder to /var/www/html/ through bindfs. This way every time you load a WordPress page in the browser it'll be lightning fast because it won't have to access and read the Host files on every request. The WordPress files are part of the Linux container. When you make changes to your code those changes will reflect on the container temporary folder and bindfs will instantly sync those changes over to the public container folder, and same the other way around. All changes made on the public folder will be synced over to the temp folder, and from there to your Host project files.