Docker is one of the most popular container management platforms amongst the IT companies and it has the capability of running on both, Linux-based and Windows-based systems. As it was originally designed for Linux, it’s been the first choice of the DevOps guys to host their containers on the Linux systems.
Now, there are multiple ways of hosting your container on Azure but we are going to work with Azure Docker VM Extension as it’s one of the cleanest plug and play solutions with Azure IaaS and it helps you to setup the docker while creating your Azure Infrastructure itself.
The Azure VM extensions install the tools like Docker Compose, Docker Daemon and Docker Client. You can run your workloads on the docker container or setup the whole cluster as per your requirements.
Unfortunately, as of today, this extension is not available directly on the Azure portal but it is easy to setup with the ARM Template. Let’s go through the template first which we are going to deploy.
- "properties": {
- "publisher": "Microsoft.Azure.Extensions",
- "type": "DockerExtension",
- "typeHandlerVersion": "1.0",
- "autoUpgradeMinorVersion": true,
- "settings": {}
- }
You can deploy this template via GitHub template by clicking on the "Deploy to Azure" button.
Fill in here,
Fill in the information of your VM. All the fields are mandatory to deploy the VM. You can also edit the template/params according to your need; else Azure will create the default values associated with the params you have provided for the VM.
Once the Deployment is completed, you will be able to see the resource created in that specific resource group. You will have a total of 5 resources – VM, Disk, Network Interface, Public IP Address and a Virtual Network.
Open the VM and copy the IP mentioned in the overview section of the VM. Open SSH client like Putty to connect to your VM. Fill in the details to ssh into your machine.
Enter your credentials that you have setup while creating the VM.
Once connected, check if the docker is setup already and working by running the command
docker -v or docker --version
if the above commands give you the version number that means you’re good to go. You can now work on the docker container and run your container.
We now try to run a simple nginx server on port 80 and expose it on public port 80. As it’s a fresh VM, the azure VM won’t have nginx image on local so it will pull it from dockerhub.
docker run -d -p 80:80 --restart=always nginx
Now as the nginx server is properly setup and running on port 80. You can hit the IP or the DNS (can be found on the Azure portal) on the web browser to see your application running.
Summary
Running a docker container on Azure is pretty easy with PaaS and IaaS solution. We have ARM templates which can be easily deployed and the infrastructure can be ready in minutes with docker up and running.