Running Wordpress with Docker

Wordpress is one of the best, if not the best, content management / blogging systems available today.  It is open source, self-hostable, and free to run.  As with many of the open source projects, should you determine you'd rather have someone else manage your blog for you, then you can setup a blog at, and this helps support the open source efforts of the platform.

In this articla, and the associated video, I'll show you how to install and run Wordpress in Docker using Docker Compose.  I'll also point out how to avoid some of the setup woes you might find if you wanted to switch to a wordpress with a domain / subdomain URL and SSL encryption.

What you'll need

  1. A server or machine to host your Wordpress and docker install.
  2. A domain name you'd like to use to access your Wordpress install.
  3. Docker (we'll go through the install on Ubuntu / Debian below).
  4. Docker-compose (again we'll go through the install on Ubuntu / Debian below).
  5. About 30 minutes.
  6. If you're running this from inside your local area network, and want to access it from the internet, you'll also want an understanding of Port forwarding, and a reverse proxy (I'll be using NGinX Proxy Manager).

Install Docker and Docker Compose

sudo apt update

sudo apt install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL | sudo apt-key add -

For Ubuntu 18.04 Bionic use the line below

sudo add-apt-repository "deb [arch=amd64] bionic stable"

For Ubuntu 20.04 Focal use the line below

sudo add-apt-repository "deb [arch=amd64] focal stable"

sudo apt update

apt-cache policy docker-ce

sudo apt install docker-ce -y

sudo usermod -aG docker ${USER}

Now install docker-compose

sudo apt install docker-compose -y

Now Let's install the Wordpress and DB software

In your home folder create a new directory.  Call it what you want, but just calling it "wordpress" is fine.

mkdir wordpress

Now, move into that directory:

cd wordpress

In this new directory, we want to create a file called "docker-compose.yml"

nano docker-compose.yml

In this file, we want to add the following code:

version: '3.3'

     image: mysql:5.7
       - db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: <a strong password>
       MYSQL_DATABASE: <give a name that makes sense>
       MYSQL_USER: <your name>
       MYSQL_PASSWORD: <a password for your user>

       - db
     image: wordpress:latest
       - "8000:80"
     restart: always
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: <use the same user as above>
       WORDPRESS_DB_PASSWORD: <use the same user password as above>
       WORDPRESS_DB_NAME: <use the same db name as above>
    db_data: {}

Make sure to replace the text inside the <  and > symbols.  The fields in each section must match as below:




NOTE: You may also need to change the left side of the port mapping (8000:80) from 8000 to a port that is available on your machine.  If not, it's fine to leave it as 8000.  Regardless of what you set it to, just remember what you set it to.

Now, save and exit nano with the following key combination:

CTRL + O, then Enter / Return to save.

CTRL + X to exit nano.

Let's Bring Up our Containers.

Now, we just need to run Docker Compose on our new .yml file.

docker-compose up -d

This should pull down the MySQL and Wordpress images from Docker, and link them together.

When you see it's done, indicated by 'done' being displayed after each container name, open a new browser tab, and enter the ip address and port number you set.

e.g. is what I should use your own machinne IP and port to ensure you see the 'Select language' page of the Initial Wordpress Install wizard.

Before we continue, we should run through this install wizard.  So, fill in the relevant data, and when you get to the Success page.  Click 'Login'.

Login to your fresh install, and you'll see the admin page for yoru wordpress system.  You can now start theming, installing plugins, and more.  If you only want to run this site locally, then you're done.  If, however, you want to run this site with a domain name, we have a bit more to do.

Setting Up Wordpress for Access via Domain / Sub-Domain

I have setup a wildcard A record for my domain ''.  Essentially, just create an A record with an asterisk ( * ) as the subdomain, and then I point that to my home IP address.  What this gives me is the ability to create subdomains for and have them immediately route to my home IP address without having to make an A record for each one.

Next, you'll want NGinX Proxy Manager installed and running on a machine in your network, or on the same machine ideally.

With NGinX Proxy Manger (NPM from now on) installed, we will create a new host, and point it to our install.  

But first... we need to make a change to our Wordpress install in the settings.

In your Wordpress admin section, click Settings >> General.  On that page, replace the Wordpress Page URL and Site URL fields with the domain URL you want in the end.  

I setup a page called  So, in those fields, I setup

Go ahead and set the other settings on that page, then click Save at the bottom of the form.  Be aware that when you click Save, it will try to reload the page with the new URL, which we haven't setup yet, so it will give a 404 error.  Don't sweat it, we'll fix it.

After you click save, let's go setup our NPM site.  Inside NPM click to add a new Host.  On the Details tab, enter the URL you want, in my case I entered  You should enter the name you want.

Next, enter the docker0 IP address of your machine if you are funning NPM and wordpress on the same machine, otherwise enter the local IP of the machine for your netowrk.  

You can use the command ifconfig or the command ip addr show to find the interfaces, and their associated IPs.

Now, enter the port you set for your wordpress install.  I used 9021, but you need to enter what you used... it was defaulted to 8000.

Click 'save', and now try your URL to make sure you are taking to your Wordpress home page (not the admin page).

If it worked, we are almost there.  Now, edit the Host entry in NPM, and go to the SSL tab.  

In the dropdown, select to Request a New Certificate. Click the 'Force SSL' option, enter your email address, and then click the 'Agree'.  Now click Save again, and be patient.  It may take a minute to get the SSL certificate.

If you don't get any error, and the pop-up window on NPM closes, try your URL again.  It should now take you to the SSL encrypted page, and show the lock Icon in the browser bar.  

Done!  Good job.  To access your admin page, just put the domain with /wp-admin at the end, and you can login to your install admin page.


Now you can get busy building something amazing wtih wordpress.