WordPress is a widely used system, although, for most developers, it's a bit of a thorn in their eyes.
I'm personally a big believer in the right tool for the job, and sometimes it can be WordPress.
Being a long-term developer, I remember when one had to set up MAMP/XAMP and struggle to get your WordPress installation to work.
Luckily in this modern day and age, we have the fantastic tool called Docker, making our WordPress installation a one-file wonder system!
And today, I'll guide you into setting up WordPress via a Docker container on your system!
To work with this tutorial, all you need to have installed is the Docker Desktop app.
You can download Docker Desktop from their website and follow the install instructions.
Set up WordPress in Docker permalink
Let's start by creating a new folder and navigating to it. I'll be using my terminal for this:
mkdir wordpress && cd wordpress
In this folder, create the
I'll be going through the elements of this file step by step. First, let's define the version of compose.
Then below, we define our services:
# Our services
We need a database image and the actual WordPress image for the WordPress site.
Let's start by adding a MariaDB image.
I'm using the
mariadb image and attaching mysql data to persist our database even when we stop our image. Then I added the port mapping from my SQL client tool to open it up.
I'm using 3307 because my native system is always running a database on 3306 that I don't want to stop.
And lastly, we provide the variables containing our login information for the database.
The next image we need is the WordPress one, and luckily for us, there is one already pre-made!
# All DB stuff (see above)
This image depends on the database, ensuring it spools up correctly. It also has its data structure attached to use our themes and plugins at one stage.
Then we open up the port to host on port 8000. As well as the environment variables to connect to our database instance.
The last element our file needs is the
Time to try this out.
docker-compose up to spool up the instances in the folder. This might take a minute or two the first time.
If you then look at your Docker Desktop app, you should see something like this:
Visiting our WordPress site powered by Docker permalink
Now let's open a browser and navigate to
http://localhost:8000/. The WordPress installation page will welcome you:
Choose the language you prefer and click on the next step, where you can choose a login name for the WordPress admin panel.
And finally, you can log in using the user you just created in the step above.
Pretty cool right, that's how easy it is to get WordPress set up in Docker.
Connecting to the database permalink
I hope this article was helpful and you have been able to get your WordPress website set up in Docker. If you have any questions feel free to reach out to me.