Azure just announced Container Instances which let you quickly spin up a container without worrying about VM provisioning and other boring stuff. Christos Matskas just posted a tutorial on using the new shiny using his MacBook as his dev machine. As my current dev env is a Surface SP4 running Windows 10 I thought I’d try it out there, using Bash for Ubuntu on Windows for extra fun. In the process, I discovered that Docker for Windows comes with a CLI so you could probably use the same commands in cmd, PowerShell or Cygwin. The point is the command are all
docker and the
Dockerfile commands run the in Docker daemon context which is Linux containers (by default).
It turns out the process is pretty much as Christos describes, except you run Docker for Windows. I did hit a few wrinkles that took a while to resolve in some cases.
Here’s the outline instructions
- In azure make sure you subscription is registered to use the new Container Instances – see https://aka.ms/rps-not-found
- You need a 64 bit machine with 64 bit Windows
- Install Docker for Windows. Logout / in to start the Docker daemon (service).
- In Docker Settings / General enable “Expose daemon on tcp://localhost:2375 without TLS”
- In Docker Settings / Network select the fixed DNS “22.214.171.124”
- This was required to over come connection errors to the Azure Container Registry. YMMV
- Install and/or update to latest Bash for Ubuntu for Windows.
- In bash run this to setup the docker client (which attaches to the Docker for Windows daemon)
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.bashrc
- In bash run a few test docker commands eg
docker ps && docker version && docker run hello-world
The COPY command in the Dockerfile failed for me and I needed to change the src path to
./bin/release/netcoreapp1.1/ubuntu.16.10-x64/publish. It seems the FROM command pulls to different location on Ubuntu compared to OS X. Also the ENTRY parameter should be
At this point you should make sure your container runs correctly with a
docker run <image-name> just to be sure everything is ok.
There appear to be a few .NET build artefacts in the project folder which will get unnecessarily copied to the Docker container. You might want to add a
.dockerignore file to trim it down a bit and reduce the push time to the registry.
I noticed that when I created the ACR it shows up as SKU
classic in the portal but the json returned form the creation command indicate it *is* basic as specified in the command. Seems like a bug.
Now it should simply have been a matter of creating the container instance. But I’m still waiting 🙁 Something is very broken. I’ll probably kill the resource group and start again. I tried deleting the containerGroups but it makes no difference.
So I ran the command to create the Container Instance, but the CLI status check never moved from ‘Creating’. I checked the portal log and it showed an error.
The subscription is not registered to use namespace 'Microsoft.ContainerInstance'. See https://aka.ms/rps-not-found for how to register subscriptions.
Nice. The instructions were clear so I simply updated my
Visual Studio Enterprise: BizSpark` subscription. But there appears to be no way to delete the remaining zombie container groups in the portal. Still, I found you can from the Azure CLI using
az container delete . Even after deleting, the names are effectively still in use (get a message that they are still transitioning). So, I tried creating with a new name but they never get provisioned either. In the end I deleted the resource group and started again and all worked. If you follow the above instructions you’ll check this registration first.
A quick one hour experiment ended up taking *much* longer. But still, I learnt plenty about Docker and Azure Containers
It would be nice if the create container instance command had a busy indicator like the ACR create does. That would save polling to see if done. It actually takes quite a while before it is up and running, certainly not as fast as some of the claims I’ve heard.
OH – don’t forget to delete your container as you’re charged for it by the second.