Docker for Azure needs a little more work up-front before we can deploy. Luckily, Docker have made this as simple as possible by providing the Azure command line interface as a container.
We need to create a service profile and resource group for our deployment to use, to do this simply run the following command:
docker run -ti docker4x/create-sp-azure bootcamp-sp bootcamp-resource westus
This will download the Azure CLI. The three variables we are passing the command are as follows:
After a few seconds, you should receive a URL and an authentication code:
Open https://aka.ms/devicelogin/ in your browser and enter the code you were given, which in my case was DQQXPYV7G:
As you can see from the screen above, the application is identifying itself as Microsoft Azure Cross-platform Command Line Interface so we know that the request is right; clicking on Continue will ask you to login. Once logged in you will receive confirmation that your request has been authorised and the application has logged in.
After a second or two you should see your command line spring into life, the first thing it will do is ask you which subscription it should use:
Select the right subscription, and then leave the command to finish, it will take around five minutes to complete. At the of the process you should receive your access credentials, make a note of these as you will need them to launch your stack:
Now that we have completed the preparation it is time to launch the Docker for Azure template, you can view the template at the following URL:
https://download.docker.com/azure/stable/Docker.tmpl
And to launch it simply go to the following URL in your browser:
You should already be logged in from authorizing the command line interface, if not login and you will be take a to a page which asks for several pieces of information on how you would like your stack to look:
To quickly copy your public SSH key to your clipboard on a Mac or Linux run the following command (changing the path to your own key if needed):
cat ~/.ssh/id_rsa.pub | pbcopy
Make sure you tick the box next to I agree to the terms and conditions stated above, once you are happy with the contents of the form click on Purchase. This will kick off your deployment, the process will take several minutes, once complete your dashboard will have a new resource added to it, depending on your existing resources you may have to scroll to see it or the page may need to be refreshed.
Clicking on See more in your resource tile will give you a list of all the resources created by Docker for Azure:
You should be able to see two public IP addresses assigned, one for a externalLoadBalancer-public-ip and one for a externalSSHLoadBalancer-public-ip make a note of both as we are going to need them, to find out the IP address click on the resource to find more information.
Now that we know the two IP addresses we can SSH into our manager node, SSH is listening on port 50000
, so to SSH to the node run the following command making sure you use the externalSSHLoadBalancer-public-ip address:
ssh [email protected] -p50000
Once logged in, run docker node ls
and you should see your three worker nodes, if you don't they may still be starting so give it a few minutes more:
As with Docker for Amazon Web Services, you are SSH'ed into an Alpine Linux host.
Meaning that to install Git we need to change to the root user and using APK to install it:
sudo su - apk update apk add git
Once Git is installed we can check out the Bootcamp repository using;
git clone https://github.com/russmckendrick/bootcamp.git
And then launch our application stack using the following command:
docker stack deploy --compose-file=/root/bootcamp/chapter04/cluster/docker-compose.yml cluster
And make sure everything is running by executing:
docker stack ls docker stack ps cluster
Putting the externalLoadBalancer-public-ipaddress into your browser should show you your cluster application. Again, using the CURL command should show us that traffic is being distributed across our containers (remember to use your own Load Balancer IP address):
curl -s http://52.160.105.160/ | grep class=
There you have it, we have successfully deployed Docker for Azure and our cluster application. The last thing to do is to delete the resources so that we do get any unexpected bills, to do this select Resource groups from the left-hand menu and then click on the three dots next to the bootcamp-resource entry and select Delete.
It will take about 10 minutes to remove all the resources and the group, but it is worth keeping the Azure portal open until the deletion process has completed as you do not want to incur any additional cost.
Depending on how long the resources were live this entire demo would have cost less than $0.10.
3.12.71.115