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”
Change directory to the newly created folder
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 “run.sh”.
Create “run.sh” with following contents.
#!/bin/sh docker run --name MyMySQL -e MYSQL_ROOT_PASSWORD=Password -p 3306:3306 -d mysql:5.7
Make the script executable
chmod +x run.sh
Then, run the script.
docker@default:~/mysql$ run.sh 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 5ffc4ff55121c1297a5c82db1f61196d581890e06077b75d31361e4c0b554617
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”
#!/bin/sh 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 run.sh
docker@default:~/wordpress$ run.sh 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 ba2eac7818aa420a36218cf63fdad70684e05d3185edba287ad4f1b7f9a69334
Fire up a browser on your Windows machine and go to “http://192.168.99.100” and you should see WordPress Installation page!