How to install WordPress with Docker on Ubuntu 16.04

Before we start, it is necessary to install Docker and Docker Compose. On Ubuntu 16.04, this can be done in two different ways:

  • Set up repositories and install from them, for ease of installation and upgrading tasks
  • Downloading the DEB package and installing it manually; also allowing you to manage upgrades completely manually

In this tutorial Docker will be installed using the repository method. So, you’ll need to install packages to allow apt to use a repository over HTTPS:

# apt install -y --no-install-recommends apt-transport-https ca-certificates curl software-properties-common

Next, add Docker’s official GPG key:

$ curl -fsSL | sudo apt-key add -

The key ID should be 58118E89F3A912897C070ADBF76221572C52609D, so verify:

$ apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D

Set up the stable repository using the following command:

# add-apt-repository \
       "deb \
       ubuntu-$(lsb_release -cs) \

Now it’s possible to install Docker.

First, update apt package index:

# apt update


# apt install docker-engine

This will install docker and its daemon should start automatically.

Install Docker Compose

After installing Docker, the next step is to install Compose, which is required for this process. Just execute the command:

# curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Change permissions to docker-compose binary:

# chmod +x /usr/local/bin/docker-compose


$ docker-compose --version

Now Docker and Docker Compose are installed and ready to be used.

Install MariaDB

Create an empty directory, for instance docker_wordpress.
Then change into it:

$ cd docker_wordpress

Create a docker-compose.yml file that will start your WordPress blog and a separate MySQL instance with a volume mount for data persistence.
In this file, enter the following text:

version: '2'

     image: mysql:5.7
       - db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

       - db
     image: wordpress:latest
       - "8000:80"
     restart: always
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress

Next, in the docker_wordpress folder, start the container using the following command:

# docker-compose up -d

It’s just that easy because the Docker team ensures that everything is well configured. In fact, there’s a script inside the WordPress Docker container that reads the MYSQL_ROOT_PASSWORD variable from the wordpress container and uses that to connect to WordPress.

Install PHPMyAdmin

Adding PHPMyAdmin it’s no different than adding a database. It is possible to use a community driven docker image. In the docker-compose.yml file, just add the following lines under the “services” section:

image: corbinu/docker-phpmyadmin
    - wordpress_db:mysql
    - 8181:80
    MYSQL_ROOT_PASSWORD: wordpress

Save these configurations and run the docker-compose command to create and start the container:

# docker-compose up -d

Configuration is almost complete! With a web browser, go to the URL: http://SERVER_IP:8181. It will show the login screen of PhpMyAdmin. Login using the same credentials that have been configured in the docker-compose.yml file.


That’s all! Now the server is running WordPress in a secure and isolated container. Although Docker is a “tool for developers”, it can be used for various projects, just like the one shown here. Of course, configuration files can be edited and customized with more fine-grained details, like a DNS section and some hardware limits like CPU and memory usage. 

  • ubuntu, docker, wordpress
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to change maximum upload size in php.ini

  There are a few common errors that occur in Wordpress and other PHP-based programs that use...

How to change the primary IP address of a cPanel server

Steps in WHM: Log into WHM and go to Basic cPanel & WHM Setup Change the Primary IP here...

How to enable the gzip/deflate in nginx server on a Linux or Unix system

Ever thought of enabling gzip compression on nginx web server for JS/CSS/HTML files? Here is...

How to Upgrade Kernel to Latest Version in Ubuntu

It is important to keep your systems up-to-date, here we'll show you how to upgrade your kenerl...

How to configure SQL server in Linux

Problem You installed SQL Server on Linux and need to customize the default installation, for...