Tutorials How to install WordPress with Docker

How to install WordPress with Docker

Try UpCloud for free! Deploy a server in just 45 seconds

WordPress is one of the most popular content management software (CMS) due to its multitude of features and ease of use. However, setting up a new web host environment can be time-consuming especially if you need to do it often. Simplifying the installation process to a few fast commands greatly reduce the time and effort required, this is where Docker comes in. Installing WordPress with Docker is a breeze, read ahead to find out more.

WordPress with Docker

Docker is a container platform that allows simple and fast software installations on any system and OS. It wraps the piece of software in a complete file system that includes everything it needs to run such as code, runtime, system tools and libraries. This allows anyone to package an application with its dependencies into a standardized building block.

Install Docker

Installing Docker itself is already easy. Firstly run the usual update command for your system to make sure you have the latest source lists.

# Debian and Ubuntu
sudo apt-get update
# CentOS
sudo yum update

Check that you have the curl command line utility.

curl -V

It comes preinstalled with most Linux distributions, but if it can not be found, install it manually with the appropriate command for your OS.

# Debian and Ubuntu
sudo apt-get install curl
# CentOS
sudo yum install curl

Use the command below to download and install Docker. The process requires root privileges so you will be asked for your sudo password on any non-root user.

curl -fsSL https://get.docker.com/ | sh

Towards the end of the installation process, you will see a suggestion to add your username to the Docker users group. Doing this allows you to run Docker commands without needing to invoke sudo every time.

sudo usermod -aG docker <username>

Log out and back in again after adding yourself to the Docker users group before continuing.

You can check that the installation was successful with the following test program:

docker run hello-world

You should see an output similar to the example below.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
Hello from Docker.
This message shows that your installation appears to be working correctly.

If the command does not work immediately, restart the Docker service with the following and try to run the hello-world app again.

sudo systemctl restart docker

Docker should now be installed and working correctly. Continue on below with the rest of the WordPress setup.

MariaDB in a container

Before installing WordPress with Docker you will need to have somewhere to store the data. MariaDB is a community-developed relational database management system and a drop-in replacement for MySQL. It is officially available on Docker and provides easy instructions with up to date images.

Start off by making a new directory where you wish to store the files for WordPress and MariaDB for example in your home directory.

mkdir ~/wordpress && cd ~/wordpress

Downloading and installing a new MariaDB container can all be performed with a single command. Before jumping in check the required parameters.

MariaDB Environment variables are marked in the Docker command with -e:

  • -e MYSQL_ROOT_PASSWORD= Set your own password here.
  • -e MYSQL_DATABASE= Creates and names a new database e.g. wordpress.

Docker parameters:

  • –name wordpressdb – Names the container.
  • -v “$PWD/database”:/var/lib/mysql – Creates a data directory linked to the container storage to ensure data persistence.
  • -d – Tells Docker to run the container in daemon.
  • mariadb:latest – Finally defines what to install and which version.

Then run the command below while replacing the <password> with your own.

docker run -e MYSQL_ROOT_PASSWORD=<password> -e MYSQL_DATABASE=wordpress --name wordpressdb -v "$PWD/database":/var/lib/mysql -d mariadb:latest
Status: Downloaded newer image for mariadb:latest

If Docker was successful at creating the container, you should see a code at the end of the output similar to the example above. You can confirm that the MariaDB container is running by using the following command:

docker ps

Check the status for your MariaDB install, it should show “Up” and the time it has been running like in the example output below.

CONTAINER ID IMAGE          COMMAND                CREATED        STATUS        PORTS      NAMES
14649c5b7e9a mariadb:latest "/docker-entrypoint.s" 12 seconds ago Up 12 seconds 3306/tcp   wordpressdb

Other useful commands for working with containers are ‘start’, ‘stop’ and ‘remove’.

docker start <container name>
docker stop <container name>
docker rm <container name>

You can find out more about available commands and options for specific commands.

docker --help
docker <command> --help

Full command-line documentation is also available over at the Docker support page.

WordPress with Docker

Applications in containers run isolated from one another in the userspace of the host operating system sharing the kernel with other containers. This reduces the overhead required to run packaged software while also enabling the containers to run on any kind of infrastructure. To allow applications within different containers to work with one another Docker supports container linking.

WordPress is also made officially available on Docker Hub, pull the image using the command below. When the version to download is not specified Docker will fetch the latest available.

docker pull wordpress

WordPress container also takes environment variables and Docker parameters:

  • -e WORDPRESS_DB_PASSWORD= Set the same database password here.
  • –name wordpress – Gives the container a name.
  • –link wordpressdb:mysql – Links the WordPress container with the MariaDB container so that the applications can interact.
  • -p 80:80 – Tells Docker to pass connections from your server’s HTTP port to the containers internal port 80.
  • -v “$PWD/html”:/var/www/html – Sets the WordPress files accessible from outside the container. The volume files will remain even if the container was removed.
  • -d – Makes the container run on background
  • wordpress – Tells Docker what to install. Uses the package downloaded earlier with the docker pull wordpress -command.

Run the command below while replacing the <password> as you did for the MariaDB container.

docker run -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=<password> --name wordpress --link wordpressdb:mysql -p 80:80 -v "$PWD/html":/var/www/html -d wordpress

Then open your server’s domain name or IP address in a web browser to test the installation. You should be redirected to the initial WordPress setup page at http://<public IP>/wp-admin/install.php. Go through the setup wizard and you are done.

WordPress initial setup page

If you get an error linking your server’s public IP address to the WordPress container’s internal address, remove the failed container using the following command:

docker rm wordpress

Restart Docker and the database container, also make sure no other service is already bound to port 80.

sudo systemctl restart docker
docker start wordpressdb

Then try creating the WordPress container again.


Congratulations, you should now have a simple WordPress with Docker running in a container and an easy way to configure another one if needed. Before continuing on building your new WordPress site, make sure to pay attention to the security on your server. To find out more, check out our article for How To Secure Your Linux Cloud Server.

Editor-in-chief and Technical writer at UpCloud since 2015. Cloud enthusiast writing about server technology and software.

48 thoughts on “How to install WordPress with Docker

  1. Hi, I am a bit confused. What does Docker actually do? Does it allow us to scale WordPress to multiple servers without the downtime and automatic replication?

    1. Hi Prasad, thanks for the question. Docker packages WordPress into a neat little container that is easy to manage. For example, it allows you to deploy multiple instances of WordPress onto the same server while keeping them separate from one another. The scaling you are referring to is something more akin to a cluster that Docker Swarm is then intended for.

      1. Hi Janne, any chance you might have a tutorial on how to deploy multiple instances of WP onto the same server too?

        1. Hi Jonathan, thanks for the question. Deploying multiple WP instances on a single server is pretty easy using Docker but you’ll need a proxy to direct connections to the right web site. Unfortunately, we don’t have a tutorial for this right at this moment but I’ll mark down a request for one.

  2. Hello, don’t you guys have autopWordpress image.

    I signed up opnUpCLoud and was trying to deploy a new server for my WP website, but I can’t find any WordPress image, Only Were listed their and as I am not so Technical Sound, it’s very hard for me to instal lwordpress manually…

    Will your team helping It.

    1. Hi there, thanks for reaching out. Our cloud images are clean slates with no preinstalled software like WordPress but it’s really easy to install, for example, using Docker like described in this tutorial. Give it a go and see for yourself 🙂

  3. Thank you for this article. It really helped e a lot.

    What if I need to install more than one WordPress site? What do you recommend? A single MariaDB container and various WP containers!?!

    Thanks again!

    1. Hi Gustavo, thanks for the question. Indeed, you could reuse the database container but it’s not necessary and having a separate DB for each WordPress container would likely be easier to manage. Please note though that you will need a reverse proxy to be able to access multiple WP sites running on a single host, for example using Nginx.

  4. I had to put `-d wordpress` at the beginning, after `docker run`, or else it gave me a `exec: –: invalid option` error.

    1. Hi Benji, thanks for the comment. The error likely happened if you try to execute the run command twice. Using docker exec -d wordpress lets you start the already created container.

  5. Installation is a bit complicated for non-techie, I have researched that upcloud performs better than Linode, If I want to install multiple websites in a single server how to do that, any guide?

    1. Hi there, thanks for the question. If you want to install and maintain multiple websites on a single server, I’d recommend having a look at Cloudron. While it requires a little setup, it’s not that difficult if you follow our tutorial for getting started with Cloudron.

      1. what does mean by multiple websites on a single server.
        Like here we have upcloud.com is a website on a server (godaddy).
        and my website is showing blog for one container
        and if I change the container of shop website
        It will show me the new shop website with upcloud.com?
        Kindly clear it.

        1. Hi Suny, thanks for the question. You are right that if you have a domain name configured for your web server and change the running container, the new website will respond instead. However, the above comment refers to running multiple websites on a single server at the same time. This can be done easily by using an application management system such as Cloudron.

  6. Hi, if I want to add a domain to my website, how would I do this? Also, could I migrate my wordpress website in a standard wordpress way(e.g. follow other tutorials) to another server?

    1. Hi Stanley, thanks for the question. To set a domain to your WordPress site, you’ll need to create an A record with your domain name registrar. As for migrating an existing WordPress site, you can simply copy the HTML directory from your current web server to ~/wordpress/html which is linked as a directory volume into the container. However, you’d also need to migrate your database and start the MariaDB container using the existing database.

  7. Hey @Janne Ruostemaa, this is a very nice tutorial. It would also be much awesome if there is a part 2 that outlines multiple WP sites with swarm setup, assigning domain names and https too! 🙂 Thanks!

    1. Hi Carl, thanks for the suggestion. We certainly like to hear feedback on our tutorials and will take your request into account when planning new additions.

  8. Hi, i’m a noob in Docker.

    I have installed WordPress with Docker (SO: Win 7)

    I can’t login using docker-compose and the yml file. I had this problem: “MySQL Connection Error”.

    So, i found your post and did that:

    $docker run -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=wordpress –name wordpressdb -v “$PWD/database”:/var/lib/mysql -d mariadb:latest

    $docker pull wordpress

    $docker run -e WORDPRESS_DB_PASSWORD=password –name wordpress –link wordpressdb:mysql -p 8083:80 -v “$PWD/html”:/var/www/html -d wordpress

    I could enter to the initial WordPress setup page at;
    and it work it!

    I could work with my site, but then i rebooted the PC and now, i can’t access to my site.

    The container’s status were “Exited”. So, i restarted the containers, but wordpress appared as if i have never used it.

    1. Hi Javier, thanks for the question. As you noticed, restarting your computer will require you to also restart the docker containers. However, you can have any changes saved by using the volume folders. You need to start the containers with the same volume parameters e.g. -v "$PWD/database”:/var/lib/mysql to continue where you left off. Docker-compose is the easiest way to do this by simply calling docker-compose up -d to start your WordPress site again after a reboot.

      1. Thanks for the answer.
        So, I have to start the containers running:

        $docker start #id_container -v “$PWD/database”:/var/lib/mysql

        or using docker-compose?

        1. I start the containers, and then I make the docker-compose file and execute “$docker-compose up -d”
          I got the message:
          “Creating wordpress-compose_mariadb_1 … done
          Creating wordpress-compose_wordpress_1 … done”
          But when i go to my site, i don´t have my last site.

          1. If you already had manually started your WP and database containers, compose created a new pair. Just stop the old containers and copy the html and database folders of your first WordPress site to where your docker-compose.yml file is saved. Then restart the site using docker-compose.

          2. I used docker-compose with the same run command’s data and i can access to wordpress, but when i reboot, i can’t start the db_container.
            It starts, but the status inmediatly changes to “Exitted”

            Thanks for your answers.

  9. Hi thanks for your sharing, I’ve got an issue when I followd your instruction when

    docker run -e MYSQL_ROOT_PASSWORD= -e MYSQL_DATABASE=wordpress –name wordpressdb -v “$PWD/database”:/var/lib/mysql -d mariadb:latest

    The screen was shown
    “docker run” requires at least 1 argument.
    See ‘docker run –help’.

    Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG…]

    May I know the reason?

    Thanks for your help

    1. Hi Vincent, thanks for the question. The error message indicates that docker could not read the parameters as expected. The bare minimum for running docker e.g. the MariaDB container docker run mariadb:latest . However, you also need to give the other parameters to connect the database with the WordPress container as explained in the tutorial. If you have difficulties copy/pasting the database docker run command, try typing it manually to see that there are no missing characters.

  10. Hi,
    i did everything just like You did and set My own Password and so on. but it keeps saying “Error establishing a database Connection”
    I cant fix that what is the Problem ?

    1. Hi Sayer, thanks for the question. Check that you’ve set the same password for both MYSQL_ROOT_PASSWORD= in MariaDB container and WORDPRESS_DB_PASSWORD= for WordPress. If these are correct, make sure your database container is running or try to recreate it and then restart your WordPress container.

      1. Hi. Thanks for your article. I have the same problem. I checked the docker db and this is working. I have checked the two passwords and they are the same. I have also updated the firewall with parts and services. But it still doesn’t work. Some idea?

        1. Hi Rosario, thanks for the question. If the WordPress container fails to start or stay up, you might have something already binding to port 80. Try running the following to start the WordPress container in port 8080 instead:

          docker run -e WORDPRESS_DB_PASSWORD= --name wordpress2 --link wordpressdb:mysql -p 8080:80 -v "$PWD/html":/var/www/html -d wordpress
          1. Hi,
            i have the same problem – it does not work 🙁
            Any further idea?

          2. Hi Mike, thanks for the comment. Seems an update to Docker has changed the default username which now needs to be defined manually by adding -e WORDPRESS_DB_USER=root to the WordPress container command. We’ve updated the tutorial to show the correct command.

  11. How can we provide the security (hardening the wordpress)for the wordpress application without any help from plugins

      1. The instructions are quite generic as to help in most use cases. However, you may wish to focus on the steps to limiting access, keeping all software up to date and making sure all password are secure and complex enough. As you are running WordPress on docker, you should also have a look at their security guide.

    1. Hi Mohan, thanks for the question. Plugins on WordPress are often one of the main reasons for security vulnerabilities and you should only install plugins you trust.

  12. Very informative Documentation thanks to your effort. This docker make things easy for Linux users to develop wordpress web and other applications. I may say goodbye to hard core installation and configuration in Linux system.

  13. Hi,

    Thanks for the artical.

    Just wondering what’s the “mysql” in below command (–link wordpressdb:mysql) creating WordPress container? the WordPress container is named as WordPress, while the mariadb is named as wordpressdb….

    docker run -e WORDPRESS_DB_PASSWORD= –name wordpress –link wordpressdb:mysql -p 80:80 -v “$PWD/html”:/var/www/html -d WordPress


    1. Hi Chance, thanks for the question. The --link wordpressdb:mysql creates an alias called mysql for the wordrpessdb container within the wordpress container. This allows you to use MariaDB container as a drop-in replacement for MySQL without having to change anything in the WordPress container itself.

  14. Excellent easy to follow guide. Quite new to docker and this helped a treat. Thanks again.

  15. Thanks this was the easiest tutorial I could find on running WordPress on Docker. I’m new to docker so I’m not sure what command the run if I do a reboot of the machine? If you could clarify that for me please?

    1. Hi Jaco, thanks for the question. You can manually start the containers by running the following command.

      docker start wordpressdb wordpress

      It’s also possible to have Docker restart the containers automatically by enabling a restart policy. Update the policy on the currently running containers by using the command below.

      docker update --restart unless-stopped $(docker ps -q)

      Now the containers should be restarted when the Docker daemon starts at boot.

  16. Well, I tried all these recipes, and guidelines along the web none worked out so far. Every guide have their own glitch, it either does not work straight from the yaml file, or end up with not being able to communicate with the maria db at all no matter what (including user names, passwords, ports, and so on.)

    Just curious, whats the deal with creating a new database inside docker? Say I have a synology already, I would already have my own DB running. Obviously, the only major reason why people want to use docker WordPress is to run a second website.

    So in this case, why are you insisting on using maria 10 db in docker rather than to use the existing one already?

    1. Hi Dennis, thanks for the comment. Sorry to hear you are having difficulty completing the steps in the tutorial. The process outlined here assumes a rather clean starting point. For example, a newly deployed Cloud Server. It’s possible to follow the tutorial on many other systems but you might need to adapt some steps.

      As for your question regarding the database configuration. You are of course free to use an existing database you might have installed on your system, but as mentioned, the tutorial is written to not require one. The advantage of running the database within a Docker container is just that, it’s self-contained. Therefore, you can have as many independent database instances as you need.

Leave a Reply

Your email address will not be published. Required fields are marked *


Helsinki (HQ)

In the capital city of Finland, you will find our headquarters, and our first data centre. This is where we handle most of our development and innovation.


London was our second office to open, and a important step in introducing UpCloud to the world. Here our amazing staff can help you with both sales and support, in addition to host tons of interesting meetups.


Singapore was our 3rd office to be opened, and enjoys one of most engaged and fastest growing user bases we have ever seen.


Seattle is our 4th and latest office to be opened, and our way to reach out across the pond to our many users in the Americas.