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
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:
Docker uses this to limit of CPU and memory usage for containers. More info here: https://docs.docker.com/config/containers/resource_constraints/
This is another important feature of kernel used by Docker.
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: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.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.
Prometheus
Prometheus
to collect metrics from your WordPress instanceTo install
Prometheus
use Prometheus Get Start DocsTo 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
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:
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.