Using WordPress and MySQL Docker Containers

I am just starting out on Docker and so far it’s been fun. Here I am going to show how I used Docker WordPress and MySQL containers.

Before I delve into the details, I want to tell you that I am going to be working on Windows using SSH on Docker VM. If you want to know how to do that see this post here.

So let’s start. Open SSH console. We are going to set up MySQL first.

On your landing directory, create a folder for MySQL. I am going to call it “mysql”

mkdir ~/mysql

Change directory to the newly created folder

cd ~/mysql

We are going to use official Docker MySQL image located here. Version: 5.7

Here’s the run command I am going to use. This will map port 3306 on the container to the VM thereby allowing me to access this MySQL instance using VM’s IP address and port 3306

docker run --name MyMySQL -e MYSQL_ROOT_PASSWORD=Password -p 3306:3306 -d mysql:5.7

But for ease of use I like to put the run command inside a Shell script I name as “”.

Create “” with following contents.

docker run --name MyMySQL -e MYSQL_ROOT_PASSWORD=Password -p 3306:3306 -d mysql:5.7

Make the script executable

chmod +x

Then, run the script.

[email protected]:~/mysql$
Unable to find image 'mysql:5.7' locally
5.7: Pulling from library/mysql

51f5c6a04d83: Already exists
a3ed95caeb02: Already exists
260d7505d8f9: Already exists
a65f47c75fe3: Already exists
729d0217f8db: Already exists
6dcf95bf56d1: Already exists
e9e6fbca5bcb: Already exists
6197f83904fb: Already exists
fd7e3b75ae7f: Already exists
fe9a3ecc0ca9: Already exists
310227c7e00d: Already exists
6eda8dacf10a: Already exists
Digest: sha256:151b7f0b61bbb49aa075dc5cd98f27a87a8d01985804f82466d5b6cd4a83235f
Status: Downloaded newer image for mysql:5.7

Of course, I had already done this before therefore you see “Already exists” messages. If you are doing this for the first time, image should get downloaded which could take 2-3 minutes depending on your internet connection.

Now I can test this MySQL instance using any Windows DB Client. Use following settings with obviously the password you set. Note, I am using “root” as login. This is only for demonstration. Obviously, you will disable it in production.


Once configured, you should be able to connect to the MySQL instance.


So far so good, let’s set up WordPress now.

Like MySQL, we are going to use official WordPress image from here.

But first, let’s create folder for wordpress. I am going to call it, simply “wordpress”

mkdir ~/wordpress

Change directory…

cd ~/wordpress


docker run --name MyWordpress--link MyMySQL:mysql -p 80:80 -d wordpress

Here, we are linking previously created MyMySQL container with this going to be  created MyWordpress container. Also, we are going to map port 80 of the container to port 80 of the VM.

chmod +x

Execute script

[email protected]:~/wordpress$
Unable to find image 'wordpress:latest' locally
latest: Pulling from library/wordpress

51f5c6a04d83: Already exists
a3ed95caeb02: Pull complete
a28c68f3894c: Pull complete
1818204ff701: Pull complete
13bed24ee698: Pull complete
47a69be46fce: Pull complete
ad0fd419fcb4: Pull complete
99643f9a28ad: Pull complete
18bffcea6a17: Pull complete
6c79ca568967: Pull complete
91b402b132dc: Pull complete
d59386f2c4be: Pull complete
7c9a4dfb7ff7: Pull complete
224509046cff: Pull complete
0b62561af6f2: Pull complete
e363f57dab90: Pull complete
f79a39a56bc2: Pull complete
Digest: sha256:9c78bf12ebea1b29166d49bc9456f511447899fd8ee86e64c61da52b0344a52d
Status: Downloaded newer image for wordpress:latest

Fire up a browser on your Windows machine and go to “” and you should see WordPress Installation page!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: