4 minutes
Self-hosted WordPress using Docker
While getting in touch with Docker and playing around with different methods to dockerize web services and websites, I came across some interesting articles, blog posts and tutorials. As mentioned in the introduction of my little series of self-hosted websites, I did not find the perfect tutorial covering all my wishes.
That was the reason for me to share my experiences as a Docker beginner and led to start blogging again. Maybe some individuals with similar wishes out there find useful information in my posts.
When I initially had the idea to blog about my solutions as a Docker beginner, of course there was no other way than running the blog in a Docker container. Due to a widespread use of WordPress, a ton of different ways exist.
By the time I’m writing this post, some months have passed since I initially created my dockerized WordPress blog. So unfortunately, I can’t reproduce if I found an almost-ready solution or if I created the docker-compose.yml
partly by myself.
Nevertheless, I will now describe how I’m running this WordPress blog in Docker. For the setup I’m using, three Docker containers are required:
- WordPress
- Web server
- Database
For an easy startup and maintenance, those containers are bundled in a docker-compose.yml
file. The web server is the only container allowed to speak to Traefik. It is linked to WordPress and includes WordPress’ files within the corresponding directory of nginx. WordPress again is linked to the database.

Setup of Docker containers to run Wordpress
1. Wordpress
As you might expect, WordPress is providing a Docker image on Docker Hub. The configuration is pretty straightforward. I created a named volume to provide the web server access to the WordPress files. Of course, a link to the database container is required. As shown in the figure, Traefik is not aware of the WordPress container.
|
|
2. Web server
Because WordPress’ Docker image I’m using is shipped without a web server, I need to create one in a separate Docker container. For this, I’m using an already existing nginx image from Docker Hub, tailored to the official WordPress container.
As shown in the figure, I need to link the web server container to the WordPress container and use the existing named image to get access to WordPress’ files.
The remaining configuration just increases PHP’s post_max_size
and specifies the connection to Traefik.
|
|
3. Database
Now that I have a WordPress instance and a web server, I still need a database to get WordPress to work. I chose a MariaDB Docker container which is of course officially provided on Docker Hub.
Accessing the database should at least be secured by a password protected user. So username and password, as well as the name of the database and a root password need to be set. Because my docker-compose.yml
file is tracked via Git, I put those variables in a separate file (wp_db.txt
). This file is then .gitignored
.
|
|
By nature, when a Docker container stops, crashes or is being deleted, the files changed within the container are also being deleted. In this case, our database would have been gone. That’s why I need to create a volume, to still have MariaDB’s files outside the Docker container when deleting the container.
|
|
Summary
Setting up WordPress in Docker was rather easy. There is a ton of tutorials, examples, Docker images, Dockerfiles etc. and setting up websites in Docker containers follow a certain pattern.
Putting all three parts together, my docker-compose.yml
file is looking like this:
|
|