This post is just to document my experience running docker on Azure and deploying ASPNET vNext sample HelloWeb app. I’m super excited about the docker support in Azure and ASPNET vNext and I couldn’t wait any longer to try it out. At a high level, these are the steps I took:
- Set up Docker Client on Virtual machine running Ubuntu desktop version.
- Created Docker Host VM on Azure
- Pull down the ASPNET vNext HelloWeb sample app
- Created the Dockerfile
- Build the container
- Run the container
- Create an endpoint port mapping for TCP port 80
Setting up Docker Client
While docker client can be set up on Windows and Mac OSX machines I decided to set it up as a virtual machine on my Mac with Ubuntu desktop on it.
Things we need to setup on docker client
- Install node
- Install Azure cross platform CLI tools
- Connect to Azure subscription
- Install docker client
Since azure cross platform CLI tools are written using nodejs, first thing we’ll need to do is Login to Ubuntu desktop virtual machine and install nodejs by running the command below
sudo apt-get install nodejs-legacy
Install Azure cross platform CLI tools, run command below
sudo npm install azure-cli --global
Connect to Azure Subscription
This process is very similar to azure powershell setup on windows machines. Download the publish settings file by running the command below. Command below will launch a browser session where you will need to login with windows live account after which the publish settings file will be downloaded to your local machine.
Import the publish settings file
azure account import <publish settings file>
Finally Install Docker client
sudo apt-get install docker.io
Create docker host virtual machine on azure
We are going to use azure vm docker create command to create the docker host virtual machine on Azure. It uses virtual machine extensions feature in azure to install docker once the virtual machine is provisioned. If you are not familiar with virtual machine extensions I highly recommend reading this article. For a list of virtual machine extensions see. One important thing to remember here is that you should create the docker host vm using this command from your docker client, walkthroughs online did not explicitly mention this. The reason for this is one of the things the command does in addition to creating the virtual machine and installing docker on it is that it creates the certificates needed for docker client to be able to talk to docker host. So if you don’t run this command from your docker client machine you may need to do additional steps so the docker client can properly authenticate with docker host.
If you want to see the azure vm docker create command usage simply add –help or -h switch right after azure vm docker create.Before we can create the host vm for docker we need to identify the Linux image to use, run command below
azure vm image list | grep "20150123"
output from the command above should look something like screenshot shown below, you can see the image circled in red
Run the command below to create docker host VM on Azure.
azure vm docker create ram-docker-host "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20150123-en-us-30GB" rprakashg P@ssw0rd123 -e 22 -l "West US" -u https://rprakashg.blob.core.windows.net -z "Large" -s "a8349281-7715-45c8-ac55-78787752ea7e"
Once the virtual machine is fully provisioned and running you can verify that your docker client can talk to the host by running following command.
docker --tls -H tcp://ram-docker-host.cloudapp.net:4243 info
Now that docker client and host is setup lets look at how we can run sample HelloWeb app published by aspnet team in docker.
Running ASPNET vNext sample app in docker
ASPNET team has published an excellent walkthrough here There is few things I had to do different which I will cover below.
I had some issue cloning the aspnet/home repository per the instructions in the article. I was getting a permission denied error and this had to do with how client machine authenticates with github, so I went down the path of setting up my docker client to talk to github and this really messed things up as docker client could not talk to docker host after I created new ssh key for github. This could be an issue with how I setup, ended up wasting hours :(. Finally I ended up doing an https cloning as shown below. You can find the https clone URL right on the repository page on github.
git clone https://github.com/aspnet/Home.git
Building the container image
On docker client machine running Ubuntu desktop I had to run the build command in elevated privileges using sudo, additionally I had to make sure docker client was talking to host based on a public/default CA pool by adding –tls -H tcp://ram-docker-host.cloudapp.net:4243 (which is my docker host), to pretty much every docker command I was issuing. Not sure why default settings did not work. Definitely need to investigate this further. If you have seen the same issue and have an explanation let me know. Building the container image using the command below took a long time with https v/s default setting which I think is non networked unix socket.
sudo docker --tls -H tcp://ram-docker-host.cloudapp.net:4243 build -t hellowebapp .
If you want to check the status of the above command, simply copy the id string returned by the previous command and run the command below
sudo docker --tls -H tcp://ram-docker-host.cloudapp.net:4243 logs -t <replace with id string>
Running the container
Ran into similar issues here too like build, additionally container just wouldn’t start, encountered “System.FormatException: Value for switch ‘/bin/bash’ is missing” error when I tried to run the container using the command described in article. Worked fine once I started running all docker commands using the –tls –H options.
sudo docker --tls -H tcp://ram-docker-host.cloudapp.net:4243 run -d -t -p 80:5004 hellowebapp
Verify running containers on host
sudo docker --tls -H tcp://ram-docker-host.cloudapp.net:4243 ps -a
Create an endpoint port mapping for TCP port 80
Last step as discussed in the article is to create an endpoint port mapping for TCP port 80 on docker host virtual machine. For name select HTTP from dropdown, protocol should be TCP and enter 80 as value for public port and private port. See screen show below
Finally have the sample HelloWeb app successfully running inside docker. Check it out here http://ram-docker-host.cloudapp.net/
Next steps I’m hoping to build a much more real world app in ASPNET vNext and test it out. I’ve already got my Mac machine configured for ASPNET vNext development with Sublime Text.
Huge shout out to Linux team at Microsoft and everyone in the open source community who have contributed writing various tools etc. You can see Microsoft stack is truly becoming more and more open.
Docker On Azure
Docker support in ASPNET vNext