Networknet archive Blog

Azure DevTest Labs: Run WordPress with Docker

Originally published

It had been a long time since I last used a Linux console to install packages. While taking the “Developing Microsoft Azure Solutions (70-532)” course, I learned about DevTest Labs and created an Ubuntu server image with Docker added as an artifact. I like the idea of creating and configuring images that developers, IT staff or end users can use to test applications.

image

The Ubuntu server was running, and I could connect to it through SSH. With help from Google, I found the commands to get a WordPress site running. I already knew what Docker was and wanted to try it myself.

Configure the database and WordPress containers

Bash15 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#update Ubuntu and verify docker is working
sudo apt-get update
sudo docker run hello-world
#restart docker daemon
sudo service docker restart
#create wordpress folder
mkdir ~/wordpress && cd ~/wordpress
#install mariadb engine for mysql
sudo docker run -e MYSQL_ROOT_PASSWORD=1234567ABC -e MYSQL_DATABASE=wordpress --name wordpressdb -v "$PWD/database":/var/lib/mysql -d mariadb:latest
#verify the mariadb container
sudo docker ps
#download wordpress container
sudo docker pull wordpress
#run wordpress container, make sure to use right tcp port (8080 is the one I will be creating NAT rule to my Ubuntu server)
sudo docker run -e WORDPRESS_DB_PASSWORD=1234567ABC --name wordpress --link wordpressdb:mysql -p 8080:80 -v "$PWD/html":/var/www/html -d wordpress

Configure access to the site

After completing these steps, I tried connecting to the Ubuntu server on TCP port 8080. Further reading and a look through the DevTest Lab resources showed that I needed an additional inbound NAT rule pointing to the VM and the port configured with the -p option.

image

I ran curl -I 10.0.0.4:8080 to check local connectivity from the Ubuntu server:

Bash8 lines
1
2
3
4
5
6
7
8
@UbuntuServer:~$ curl -I 10.0.0.4:8080
HTTP/1.1 301 Moved Permanently
Date: Fri, 17 Nov 2017 09:49:13 GMT
Server: Apache/2.4.10 (Debian)
X-Powered-By: PHP/5.6.32
Location: http://ubuntu1234.westeurope.cloudapp.azure.com:8080/
Content-Type: text/html; charset=UTF-8
@UbuntuServer:~$

The output looked good, so I opened Internet Explorer and followed the WordPress installation steps to create a new site.

Start the containers after a reboot

I also learned that I needed to update the containers' restart settings. Without that change, they did not start after a server reboot. These two commands resolved the problem:

Bash2 lines
1
2
sudo docker update --restart always wordpressdb
sudo docker update --restart always wordpress

I will continue maintaining my Ubuntu server, exploring Docker containers and refreshing my Linux knowledge.