Deploying Docker containers in Azure

Posted: November 2, 2017 in Azure

Think of a Docker container as another form of virtualization. Virtual Machines (VM) allow a piece of hardware to be split up into different VMs – or virtualized — so that the hardware power can be shared among different users and appear as separate servers or machines. Docker containers virtualize the OS, splitting it up into virtualized compartments to run container applications.

Installing Azure VM

This Azure VM will include support for Docker containers

First,create Azure Resource Group,availability set and Public IP (needed for Azure docker host later on)-All steps below i run on my Windows 10 lap-top

New-AzureRmResourceGroup -Name myrg1 -Location "West Europe"

New-AzureRmAvailabilitySet -Location 'west europe' -name 'myavailabilityset' -ResourceGroupName myrg1

New-AzureRmPublicIpAddress -name 'mypublicip' -ResourceGroupName 'myrg1' -Location 'west europe' -AllocationMethod Dynamic

Now see  available Docker VM’s

Install Azure CLI open CMD and run az vm image list

az vm image list

[
{
"offer": "CentOS",
"publisher": "OpenLogic",
"sku": "7.3",
"urn": "OpenLogic:CentOS:7.3:latest",
"urnAlias": "CentOS",
"version": "latest"
},
{
"offer": "CoreOS",
"publisher": "CoreOS",
"sku": "Stable",
"urn": "CoreOS:CoreOS:Stable:latest",
"urnAlias": "CoreOS",
"version": "latest"
},
{
"offer": "Debian",
"publisher": "credativ",
"sku": "8",
"urn": "credativ:Debian:8:latest",
"urnAlias": "Debian",
"version": "latest"
},
{
"offer": "openSUSE-Leap",
"publisher": "SUSE",
"sku": "42.2",
"urn": "SUSE:openSUSE-Leap:42.2:latest",
"urnAlias": "openSUSE-Leap",
"version": "latest"
},
{
"offer": "RHEL",
"publisher": "RedHat",
"sku": "7.3",
"urn": "RedHat:RHEL:7.3:latest",
"urnAlias": "RHEL",
"version": "latest"
},
{
"offer": "SLES",
"publisher": "SUSE",
"sku": "12-SP2",
"urn": "SUSE:SLES:12-SP2:latest",
"urnAlias": "SLES",
"version": "latest"
},
{
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"urn": "Canonical:UbuntuServer:16.04-LTS:latest",
"urnAlias": "UbuntuLTS",
"version": "latest"
},
{
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"urn": "MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest",
"urnAlias": "Win2016Datacenter",
"version": "latest"
},
{
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2012-R2-Datacenter",
"urn": "MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest",
"urnAlias": "Win2012R2Datacenter",
"version": "latest"
},
{
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2012-Datacenter",
"urn": "MicrosoftWindowsServer:WindowsServer:2012-Datacenter:latest",
"urnAlias": "Win2012Datacenter",
"version": "latest"
},
{
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2008-R2-SP1",
"urn": "MicrosoftWindowsServer:WindowsServer:2008-R2-SP1:latest",
"urnAlias": "Win2008R2SP1",
"version": "latest"
}
]

Install Docker

Open CMD as admin

docker-machine create --driver azure --azure-ssh-user ja --azure-subscription-id "96b761b2-0307-45ca-a704-dc2cda5c129b" --azure-open-port 80 -azure-image "Canonical:UbuntuServer:16.04.0-LTS:latest" --azure-location "West Europe" --azure-resource-group "myrg1" --azure-resource-group "myrg1" --azure-availability-set "myavailabilityset" --azure-static-public-ip "mypublicip1"

Above command will create Docker VM in Azure but first Docker needs to login to Azure

1.PNG

2.PNG

3.PNG

4.PNG

During installation Docker will create self-signed certificates that will be used for connecting to Docker host, it will also store private key of the certificate in user profile

1.PNG

After installation finishes identify variables (needed to find out Docker IP address)

docker-machine env mypublicip1

SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://52.174.2.212
SET DOCKER_CERT_PATH=C:\Users\lap-top\.docker\machine\machines\mypublicip1
SET DOCKER_MACHINE_NAME=mypublicip1
SET COMPOSE_CONVERT_WINDOWS_PATHS=true
REM Run this command to configure your shell:
REM @FOR /f “tokens=*” %i IN (‘docker-machine env mypublicip1’) DO @%i

Connecting to Docker host

docker -D -H tcp://52.174.2.212:2376 --tlsverify --tlscacert=C:\Users\lap-top\.docker\machine\certs\ca.pem --tlscert=C:\Users\lap-top\.docker\machine\certs\cert.pem -tlskey=C:\Users\lap-top\.docker\machine\certs\key.pem ps

Install basic docker container

docker run -d -p 80:80 --restart=always nginx

Find out container’s IP address:

docker-machine ip mypublicip1

 

6

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s