skip to Main Content

I am experimenting with a wordpress docker install.
I used the basic install with mounted volumes.

docker-compose.yml

version: '3.3'
services:
   db:
     image: mysql:5.7
     volumes:
       - ./mysql:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8001:80"
     restart: always
     volumes:
       - ./html:/var/www/html
       - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress

But after adding several plugins and a theme, wp-admin gets terribly slow. Approx 5-7 seconds TTFB. Using elementor becomes basically impossible.

Throwing hardware (it’s an AWS EC2) at the server did NOT change the performance.

Is it possible to have wordpress in a performant docker setup?

2

Answers


  1. There is almost no cost of running docker. The biggest difference is on the networking layer, but it is reduced with host networking. The cost is not as much as you should think about it.

    What is docker

    In simplification docker is nothing more than process and resources isolation. All processes are running on the host machine without any virtualozation. There are linux modules responsible for isolation resources and processes. Example of modules:

    IBM investigation in 2014

    IBM did some investigation for that topic few years ago here: https://dominoweb.draco.res.ibm.com/reports/rc25482.pdf

    You can find network latency for Docker NAT networking:
    enter image description here

    But let’s see another graph, that show us latency for Redis. You can see that for network=host docker is almost as fast as native host.
    enter image description here

    Debugging

    We cannot say what is wrong with your deployment, because picture is too big, and you provided only small part of the photo.

    However you can start debugging by yourself.

    1. Create another EC2 instance.
    2. Install Prometheus on new Instance
    3. On the WordPress instance install the node exporter. This will export metrics for Prometheus
    4. Configure Prometheus to collect metrics from your WordPress instance
    5. Optionally install the Grafana on the Prometheus Server.
    6. Wait a day to collect data and analyze where you are hitting the ceil.

    To install Prometheus use Prometheus Get Start Docs

    To install node_exporter and set the Prometheus Scraper up use this docs: https://prometheus.io/docs/guides/node-exporter/

    Summary

    So answer to your question is: It depends, how your application is deployed to docker. Probably few important things, that can affect your performance

    • CPU limit for container
    • Memory limit for container
    • Networking type
    • Missing capabilities
    • Number of application deployed on the same host
    • Other limits like max open files, virtual memory limit, number of processes inside container, etc…
    Login or Signup to reply.
  2. First: You should probably use the mysql:latest tag. 5.7 is now an older database, latest is now 8.0.23 (community server).

    Second: You should specify wordpress version, and php version and keep these updated along the way. I use image: wordpress:5.6-php7.4-apache which gives me php7 for better performance.

    Once you make changes in your docker-compose.yml, run docker-compose up --build to make sure to get clean versions of everything.

    Your docker-compose version could be upgraded from 3.3 to 3.8 (has nothing to do with performance, though).

    Make sure to upgrade your Docker installation to the latest (19.03+ at the moment).

    Compare your docker-compose to mine, which is running great with plugins:

    version: "3.8"
    
    services:
      db:
        image: mysql:latest
        command: "--default-authentication-plugin=mysql_native_password"
        volumes:
          - db_data:/var/lib/mysql
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: somewordpress
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: wordpress
    
      wordpress:
        depends_on:
          - db
        image: wordpress:5.6-php7.4-apache
        ports:
          - "8000:80"
        restart: always
        environment:
          WORDPRESS_DB_HOST: db:3306
          WORDPRESS_DB_USER: wordpress
          WORDPRESS_DB_PASSWORD: wordpress
          WORDPRESS_DB_NAME: wordpress
          WORDPRESS_CONFIG_EXTRA: |
            define('WP_DEBUG', true);
            error_reporting(E_ALL);
            ini_set('display_errors', 1);
        working_dir: /var/www/html
        volumes:
          - ./wp-content:/var/www/html/wp-content
          - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    volumes:
      db_data: {}
    

    Note that I use working_dir so that the directory for your docker container is set correctly. By adding wp-content to your volumes you copy wp-content into your container to persist it. Plugins are located in wp-content and this may improve your performance situation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search