Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

docker - Is it possible to have dockerized wordpress with same performance as a wordpress server install?

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?

question from:https://stackoverflow.com/questions/65833152/is-it-possible-to-have-dockerized-wordpress-with-same-performance-as-a-wordpress

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...