Running Wordpress In Docker
> Home

I’m by no means the worlds biggest Wordpress fan, but when a client was in need of hosting for their Wordpress site, I was happy to oblige. To keep things I’d rather not have to deal with too often segregated, containers was my tool of choice, Docker being the package I’m most familiar with.

Installing Docker

sudo apt-get install docker.io
sudo systemctl start docker
sudo systemctl enable docker

Configure environment

mkdir /home/web/client1/wordpress-docker/database
mkdir /home/web/client1/wordpress-docker/html

Setting up the containers

docker pull mariadb
docker run --restart always \
           -e MYSQL_ROOT_PASSWORD=MyRootPassword \
           -e MY_SQL_USER=wpuser \
           -e MYSQL_PASSWORD=wpuserPassword \
           -e MYSQL_DATABASE=wordpress_db \
           -v /home/web/client1/wordpress-docker/database:/var/lib/mysql \
           --name wordpress_db \
           -d mariadb

docker pull wordpress
docker run --restart always \
           -e WORDPRESS_DB_USER=wpuser \
           -e WORDPRESS_DB_PASSWORD=wpuserPassword \
           -e WORDPRESS_DB_NAME=wordpress_db \
           -p 127.0.0.1:8080:80 \
           -v /home/web/client1/wordpress-docker/html:/var/www/html \
           --link wordpressdb:mysql \
           --name wpcontainer \
           -d wordpress

Advanced configuration

I like to pop the following in to uploads.ini

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

Which can then be included by referencing the file in the docker run command for the Wordpress container:

-v /home/web/client1/wordpress-docker/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

Upgrading

docker pull wordpress
docker rename wpcontainer wpold
docker stop wpold
docker run --restart always \
           -e WORDPRESS_DB_USER=wpuser \
           -e WORDPRESS_DB_PASSWORD=wpuserPassword \
           -e WORDPRESS_DB_NAME=wordpress_db \
           -p 127.0.0.1:8080:80 \
           -v /home/web/client1/wordpress-docker/html:/var/www/html \
           --link wordpressdb:mysql \
           --name wpcontainer \
           -d wordpress

Hopefully the new version works, so the old version can be removed.

docker rm wpold

However, if the new version doesn’t work, rollback to the old version.

docker rm wpcontainer
docker rename wpold wpcontainer
docker start wpcontainer

Contents