How to Install WordPress with Docker on Ubuntu 15.04

In this tutorial, we will install WordPress by using multiple docker containers. Wordpress itself in one container and the MariaDB database in another container. Then we will install Nginx on the host machine as reverse proxy for the WordPress container.

Docker is an open source project to make developers and sysadmin easier to create, deploy and run distributed application inside a docker container. Docker is an operating-system-level virtualization, you can create system isolation for your application with docker for the application that is running inside the container. You can create hundreds of docker containers inside your server, the number depends on your machine hardware.


  • Ubuntu 15.04 - x86_64
  • Root privileges
  • Docker knowledge

Step 1 - Install Docker

In this step, we will update the Ubuntu repository and then install the latest version of

Become root user for the next steps:

sudo -s

Update the Ubuntu repository:

apt-get update

Now install the Docker packages with the apt command below:

apt-get install

When the installation has finished, start docker and add it to run at the system boot time with the systemctl command:

systemctl start docker
systemctl enable docker

Next, check the Docker version with this docker command:

docker version
docker run hello-world

Docker installation is finished.

Check the Docker version.

Step 2 - Setup the MariaDB Container

In this step, we will download a new MariaDB images from the docker registry and create a new container based on that image. We will configure a new database and user for the WordPress installation.

Download the Docker MariaDB image to the system with the Docker pull command:

docker pull mariadb

Now you can see the new docker MariaDB image with the command below:

docker images

List the MariaDB Docker image.

Next, create a new container from the MariaDB image for the WordPress installation. Before creating the new container, create a new directory for the WordPress data, database directory, and the WordPress code directory.

mkdir ~/wordpress
mkdir -p ~/wordpress/database
mkdir -p ~/wordpress/html

Now create the new MariaDB container with name 'wordpressdb' with the command below:

docker run -e MYSQL_ROOT_PASSWORD=aqwe123 -e MYSQL_USER=wpuser -e [email protected] -e MYSQL_DATABASE=wordpress_db -v /root/wordpress/database:/var/lib/mysql --name wordpressdb -d mariadb

If there is no error, you can see the results below:

Create the MariaDB container.

Parameter explanation:

  • MYSQL_ROOT_PASSWORD = configure the password for the MySQL root user.
  • MYSQL_USER = create a new MySQL user 'wpuser' for the WordPress database.
  • MYSQL_PASSWORD = set the password '[email protected]' for the user 'wpuser'.
  • MYSQL_DATABASE = create a new database for the wordpress installation with name 'wordpress_db'.
  • -v /root/wordpress/database:/varlib/mysql = linked database directory to the mysql directory '/var/lib/mysql' on the container to ensure data persistance.

TheMariaDBriadb container has been created, now check the new user and the database for the WordPress installation to ensure there is no error with command on top.

From the host machine, check the wordpressdb container IP address with docker command below:

docker inspect -f '{{ .NetworkSettings.IPAddress }}' wordpressdb

Next, connect to the wordpressdb container with mysql command from the host system:

mysql -u wpuser -h -p 
TYPE PASSWORD: [email protected]

Check new database 'wordpress_db':

show databases;

All results:

Check the MariaDB database in the docker container.

The new Docker container, MySQL user, and the MySQL database for WordPress have been successfully created.

Step 3 - Setup the Wordpress Container

Once the database container has been created, download the latest WordPress docker image with the docker pull command:

docker pull wordpress:latest

When the download has finished, create a new container from the images with the name 'wpcontainer'.

docker run -e WORDPRESS_DB_USER=wpuser -e [email protected] -e WORDPRESS_DB_NAME=wordpress_db -p 8081:80 -v /root/wordpress/html:/var/www/html --link wordpressdb:mysql --name wpcontainer -d wordpress

You can get the result as below, or you can check that the new container named 'wpcontainer' has been created.

The WordPress Docker Container.


  • WORDPRESS_DB_USER = define database user 'wpuser' for the wordpress db.
  • WORDPRESS_DB_PASSWORD = password '[email protected]' for the database user 'wpuser'.
  • WORDPRESS_DB_NAME = name of the database 'wordpress_db' created on step 2.
  • -p 8081:80 = mapping the port 80 on the container to port 8081 on the host.
  • -v /root/wordpress/html:/var/www/html = Linking the web root directory '/var/www/html' on the container to the local host directory 'wordpress/html'.
  • --link wordpressdb:mysql = linking the mariadb container 'wordpressdb' to the new continer wordpress 'wpcontainer'.

To see the WordPress container running, you can check it with the curl command on the host IP and port 8081.

curl -I

Check that the Wordpress container is running.

You will see the results:

  • The web server is Apache, running on the Debian.
  • PHP 5.6 is running in the container.
  • You see the redirect to the WordPresss installation.

Step 4 - Install and Configure Nginx as Reverse Proxy

In this step, we will install the Nginx web server on the host system. We will configure Nginx as a reverse proxy for the Docker container 'wpcontainer' on the port 8081.

Install Nginx with the apt command on the host system:

apt-get install nginx

Next, go to the Nginx directory and create a new virtual host configuration for the WordPress container.

cd /etc/nginx/sites-available/
vim wordpress

Paste virtual host configuration below:

server {
  listen 80;

  location / {
    proxy_pass http://localhost:8081;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Save the file and exit.

Now, activate the new WordPress virtual host and delete the default virtual host configuration.

ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-available/default
rm -f /etc/nginx/sites-enabled/default

Restart the Nginx web server:

systemctl restart nginx

Step 5 - WordPress Installation

Open your web browser and visit the domain name on the nginx configuration '' and you will be redirected to the WordPress installation.

Type in your site title, admin username, and password, then click Install WordPress.

WordPress Docker Installation.

Now click on 'Login Wordpress' and fill in the username and password that you have chosen above, you will see the WordPress dashboard.

The WordPress Dashboard

Or you can see the WordPress home page below:

WordPress Home

The WordPress installation with a MariaDB container and a WordPress container has been successful.


Share this page:

Suggested articles

18 Comment(s)

Add comment


By: Evert

Hi there,


Have you implemented SSL yet?



By: andy

You'll want to add to isntall the mariadb-client-core package on the host otherwise you wont be able to test the SQL container.

By: Me

This is true. You will want to install the MariaDB client otherwise you will receive an error in Step 2 when running:

mysql -u wpuser -h -p

For example in Ubuntu I had to run the following:

apt-get install mariadb-client-core-10.0

After installing the MariaDB client I was then able to run the 'mysql' command to login to the MariaDB.

That being said, this is the best tutorial I have seen for getting Wordpress up and running on Docker.

By: matrixskp

Can I ask why you don't install NGINX via docker as well?

By: Rahul Sharma

Can I follow the same tutorial to install wordpress in docker on Arch Linux? (I am using Antergos)

By: yudhis

Hi, how to run it on my localhost?

By: maksud

I am unable to access mysql as mentioned steps...please healp

mysql -u wpuser -h -p


By: sagar

Me to!

ERROR 1045 (28000): Access denied for user 'wpuser'@'' (using password: YES)

By: till

This means that you use a wrong password. Ensure that you enter the exact password that you have chosen for the MySQL user 'wpuser'.

By: Dee

Got issues here, after entering this ''mysql -u wpuser -h -p''... it prompted for password and I used the same one ''[email protected]'' but it said ''ERROR 2003 (HY000): Can't connect to MySQL server on '' (111 "Connection refused")'' 

Now I am stuck here

By: Jared Stevens

I had this exact same issue. For me, installing the mariadb-client-core package on my host machine fixed the issue. If you already have mariadb installed, remove the package and reinstall the client-core package.

By: IB1


The tutorial worked fine (mostly) for me, however. Some docker networking questions pop up!The "wpcontainer" has a port mapping of>80/tcp (listed in docker ps)However! The wp-admin install is already available on my LAN from other machinse on port 8081 - how come? so if I use my LAN address i will get redirected to the wp install.

As far as I understand the port 8081 should not be exposed on my LAN through eth0, but only internally on the docker net - unless the docker is in bridge network mode (which docker ps does not tell me)? And it is mapped to port 80 internally, so inside the machine I can also curl to the wp install via

--Docker Noob who is confused!Any insight or basic info regarding this available?

By: fbifido

Can you update for the below OS + add lets encrypt:

Ubuntu 18.04 LTS

CentOS 8

Debian 10.2


By: fabien


I couldn't make the tuto work so i decided to remove all i did, but docker doesnt allow me to remove images or containers from mysql and adminer. They keep on poping back when i stop them... Pls tell me how to remove them both definatively.


By: Sakib

How to resolve this one?

$ curl -I curl: (7) Failed to connect to port 8081: Connection timed out


OS: Ubuntu 18.04 LTS

By: Chad Cotton

I can't tell when you made this comment, so I may be late to answer this, instead of using, you should use your own system's IP addrress.  When you're on the same box (machine) you can use or "localhost:8081".  If you're on another computer in the network then you might be able to use the ip-address of the computer hosting the docker container.  


Hi Arul, 

I am very happty to find exat solution.  I hope so i will learn more 

By: Tom Dings

Used your examples to create some automated routines to start some Wordpress Blog containers.Partly used at https://Start.YourBlog.Today/ too ... No complaints received yet. Thank you!