How to install WordPress with Docker on Ubuntu 16.04

WordPress with Docker on Ubuntu 16.04

Introduction

For those who don’t know, WordPress is a famous content management system based on PHP and MySQL, distributed under the terms of the GNU GPLv2 (or later).

Usually it is installed on a web server like Apache, but it is also possible to run it on an isolated environment built with Docker containers, in particular, using Docker Compose.

This is the subject of this tutorial, using Ubuntu 16.04 as the Operating System.

Getting started

First of all, it’s 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 https://apt.dockerproject.org/gpg | 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 https://apt.dockerproject.org/repo/ \
       ubuntu-$(lsb_release -cs) \
       main"

Now it’s possible to install Docker.

First, update apt package index:

# apt update

Then:

# 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 https://github.com/docker/compose/releases/download/1.11.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Change permissions to docker-compose binary:

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

Test:

$ 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'

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

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:

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:

phpmyadmin:
image: corbinu/docker-phpmyadmin
  links:
    - wordpress_db:mysql
  ports:
    - 8181:80
  environment:
    MYSQL_USERNAME: root
    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.

Conclusion

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. Have fun with it!

  • I’ve profited 104 thousand dollars in last 12 months by doing an on-line job at home a­­n­­d I was able to do it by w­orking in my own time f­­o­­r several hours /day. I used a money making model I was introduced by this website i found online and I am amazed that i made so much extra income. It’s so beginner-friendly and I’m just so happy that i discovered this. This is what i do… EASYURL.NET/9861f

  • I got paid 104,000 thousand dollars in last twelve months by working from my house and I did that by work­ing in my own time f­o­r several h /day. I used a business opportunity I found online and I am thrilled that i made so much money. It’s very beginner-friendly a­n­d I’m just so grateful that I found out about it. This is what i did… http://jump­.­wtf/CCcHHu1

  • I have earned 104000 dollars in last twelve months by working from my house a­n­d I did that by wo­rking part time f­­o­­r 3+ hrs /day. I used work opportunity I found online and I am amazed that i made so much money. It’s really user friendly and I’m so blessed that i found it. Here’s what I did… http://itreplaceitall­.­com

  • I got paid $104000 previous year by doing an on-line job at home a­­n­­d I did that by working in my own time for few h daily. I was following an earning opportunity I found online and I am so excited that i made so much extra income. It’s very beginner-friendly and I’m just so blessed that I found out about it. Here’s what I did… http://budget25­.­weebly­.­com

  • I’ve earned 104000 bucks previous year by working from my home and I was able to do it by wor­king in my own time f­o­r 3 or sometimes more hrs /day. I’m using a business model I was introduced by this website i found online and I am so happy that I was able to earn so much extra income. It’s user friendly and I’m so happy that I found out about this. Check out what I do… http://tny­.­im/8yR

  • I got paid 104,000 bucks last year by freelancing on-line a­­n­­d I manage to do it by work­ing part-time f­o­r few hours every day. I’m using a business opportunity I stumbled upon from company that i found online and I am thrilled that I was able to earn so much money on the side. It’s so beginner friendly and I’m so thankful that i found this. Here’s what I do… http://gee­.­su/xQW8I

  • I have profited $104k in 2016 by doing an on-line job at home a­n­d I did that by working part-time f­­o­­r 3+ h daily. I’m using a money making opportunity I was introduced by this company i found online and I am so excited that I was able to earn such great money. It’s so beginner friendly a­­n­­d I’m just so happy that I found out about it. Check out what I do… http://www.wzurl­.­me/tEXzrw

  • alice.masterson

    I have profited 104000 dollars last year by doing an online job at my house and I did that by w­o­r­k­i­n­g part time for several hours every day. I followed a business opportunity I came across online and I am happy that i earned so much money on the side. It’s user-friendly a­n­d I am just so grateful that i discovered it. Check out what I do… http://www.wzurl­.­me/m7IQvg

  • bell_raymond

    I got paid 104 thousand dollars in 2016 by working from my home a­­n­­d I was able to do it by w­o­r­k­i­n­g part time for 3+ hours a day. I followed work opportunity I stumbled upon from company that i found online and I am excited that i made so much extra income. It’s very beginner friendly a­­n­­d I’m so grateful that I found out about this. This is what i do… http://urlof­.­site/zmJsn

  • I was paid 104000 bucks past 12 month period by doing an internet based task moreover I was able to do it by w­orking in my own time f­o­r quite a few hours regularly. I used work opportunity I stumbled upon on the web and also I am delighted that I was manage to make such great money. It is really newbie-friendly and therefore I’m so delighted that I discovered out about it. Look into what I do… I was without work for six months time when my former Co-worker eventually advised me to start off freelancing online… That was really after I gained $5000 in my 1st 30 days when I seriously believed I really could do this for a living! Today I am happier than ever… I work from home moreover I am my own boss now like I always wanted… I see a number of unhappy people around me, working the same old boring job that is sucking the life out of them day by day… Whenever I see anyone like that I say START FREELANCING MAN! This is how I started out >>>> www­.­cat­.­org­.­uk/snip/78276

  • I was paid 104000 bucks past 12 months by doing an online work and I was able to do it by w­orking in my own time f­o­r several hours every day. I used job opportunity I found out on the web and I am excited that I was able to earn such decent cash. It is seriously newbie-friendly and therefore I am so grateful that I found out regarding it. Read through exactly what I do… www­.­cat­.­org­.­uk/snip/93439

  • lawrence_lee

    I was paid 104000 bucks previous 12 months by doing a web based job and I was able to do it by w­orking in my own time f­o­r several hours on a regular basis. I used work opportunity I stumbled upon on-line and I am delighted that I was in a position to earn such decent earnings. It’s genuinely newbie-friendly and therefore I’m so pleased that I found out regarding it. Go and visit exactly what I do… http://polr­.­me/1g1h