Setting Up Docker in Azure VM
Having leftover Azure credit from my MSDN subscription made Azure a logical choice for hosting Docker in a Linux virtual machine. This post documents the steps I took to create a convenient working environment on my Windows workstation.
Installing PuTTY as SSH Client
SSH is the protocol used to connect to a newly created Linux VM in Azure. PuTTY is probably the most popular Windows client for SSH. You should have it installed along with PuTTYgen key generation utility. The latter will create an SSH key for you that you can use to login with, instead of a password, making the login process more convenient and secure.
Both tools can be downloaded as standalone executables. Put them into a folder of your choice. Add that folder to the
PATH, as you will want to start at least
putty.exe without specifying its full path.
puttygen.exe and click on Generate to create a new SSH key. Save the public and private key to a secure location and keep the application open. You will need to copy the public key to Azure Portal when creating the virtual machine.
Creating a Virtual Machine
If you search the Azure marketplace for Docker, you can find Docker on Ubuntu Server image template, which is your best choice, unless you have some specific requirements.
Just click on Create and fill in the details: Host name and User name. Select SSH public key as Authentication type instead of Password and copy the previously generated public key from PuTTYgen into the SSH Public Key text box. Optionally change the Pricing Tier, Resource Group, and Location to your liking. Click on Create when you are satisfied with the configuration.
Configuring PuTTY and ConEmu
While Azure is preparing the virtual machine for you, you can start configuring PuTTY:
- Start in Connection > Data category and set Auto-login username to the user name you entered in the Azure Portal.
- Navigate to Connection > SSH > Auth category and select the Private key file for authentication at the bottom of the page. You need to open the private key file, which you saved from PuTTYgen when creating the SSH key.
- Return to the Session category and once the VM is created, copy the Computer name from the Azure portal into the Host Name (or IP address) text box.
- Enter a name for the Saved Session and click on Save to keep the settings for the next time.
Click Open, and if you configured everything correctly, a connection to your new VM should be established. The first time you connect, you'll need to accept the server's public key to confirm its identity. On subsequent attempts PuTTY will use it to verify that the server's identity didn't change.
- Add anew predefined task in the Setup tasks dialog
- Enter the name and optionally a hotkey
- Set Commands to:
putty.exe -new_console -load "docker-azure"(you need to have
putty.exein the path and replace
docker-azurewith your saved session name in PuTTY.
Save the settings and start the newly created task in ConEmu. It should automatically connect you to your Azure VM and log you in. It can't get more convenient than that.
Endpoints Configuration in Azure
By default, only the SSH port of your virtual machine accepts incoming connections. If you want your Docker containers to be accessible from the internet, defining the ports when running the container will not be enough. You'll need to create matching endpoints in the Azure portal, as well. Only the ports listed in the Endpoints configuration will be publicly accessible.