Hostwinds Tutorials

Search results for:


Table of Contents


Installing Docker
Launching WordPress & MySQL Containers

Install Docker and WordPress On Ubuntu

Tags: WordPress,  Ubuntu,  Docker 

Installing Docker
Launching WordPress & MySQL Containers

What is Docker? Docker is a containerization platform that performs operating-system-level virtualization, letting you run lightweight containers in isolation. The following document will take you through installing Docker and running a WordPress & MySQL container.

Installing Docker

Install docker from the official repository.

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

Use the command below check to verify the version.

docker version

Now install Docker Machine by grabbing from it's github repo and making it executable.

curl -L https://github.com/docker/machine/releases/download/v0.14.0/docker-machine-uname -s\-`uname -m` >/tmp/docker-machine
chmod +x /tmp/docker-machine
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
  1. Install Docker Compose, same as earlier and making sure it's executable.
curl -L https://github.com/docker/compose/releases/download/1.21.0-rc1/docker-compose-uname -s\-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /tmp/docker-compose
sudo cp /tmp/docker-compose /usr/local/bin/docker-compose
  1. Let's check the versions of docker-compose and docker-machine.
docker-compose version
docker-machine version

Launching WordPress & MySQL Containers

To run WordPress, you will need to run two separate containers. Besides the WordPress container, you must also install the database container.

  1. Start by pulling the docker image.
docker image pull MySQL
  1. Launch MySQL by running the following command:
docker container run -d \
   --name MySQL \
   -e MYSQL_ROOT_PASSWORD=wordpress \
   -e MYSQL_DATABASE=wordpress \
   MySQL

The command we just ran launches the MySQL in the background; we call the container MySQL by using (–name WordPress). The following two environment variables (using -e) to set the MySQL root password to WordPress (-e MYSQL_ ROOT_PASSWORD=wordpress) and created a database called WordPress (-e MYSQL_ DATABASE=wordpress).

For the sake of security, it is highly recommended to use a more complex password during your own setup.

Once you've launched the MySQL container, you should have received a container ID.

  1. Verify the container is running as expected by using the following command:
docker container ps

Supplemental step: to check the status of your MySQL container, run the following command.

docker container logs MySQL

  1. Now we install the WordPress container image.

docker image pull WordPress

  1. Launch the WordPress container
docker container run -d \
   --name WordPress \
--link MySQL:mysql\
   -p 8080:80 \
   -e WORDPRESS_DB_PASSWORD=wordpress \
   WordPress
  1. Verify the WordPress container is running as expected by using the following command:
docker container logs MySQL
  1. If you notice that it isn't on, you can start the WordPress container by issuing the following command.
docker container start WordPress

Written by Hostwinds Team  /  April 10, 2018