Docker is getting more and more popular. At Connect() 2016 Microsoft announced the Azure Web Apps on Linux that support docker. To build your containers in a CI build you need a Linux build agent. Since the documentation is scattered around I provide you with the shortest way to set up a Linux build agent in Azure.
Create Docker machine in Azure
The easiest way to set up a Docker machine in Azure is with the docker-machine command. It has a driver for Azure that lets you create the machine from within your PowerShell. Check docker-machine create –help for all options.
docker-machine create --driver azure --azure-subscription-id {subscriptionid} --azure-location westeurope --azure-resource-group {resourcegroup} {machinenameinlowercase}
If you run the command the first time you have to log in in your browser to https://aka.ms/devicelogin and enter the code from PowerShell.
The authentication is cached by the driver for two weeks.
Now you could ssh into your machine with docker-machine ssh {machinename} – but you cannot paste things to the console. So it’s better to create a putty connection. Run
docker-machine env dockerbuild
The output will tell you everything you will need in the next steps. Make sure to backup the certificates and the other files.
Configure Putty to access the machine
Open puttygen and load id_rsa. Click “Save private key” and confirm the dialog. Save the file in the same directory as id_rsa.ppk.
Now open putty. Enter the IP from the docker-machine env command.
Set the user to docker-user.
Brows for the certificate id_rsa.ppk your created with puttygen.
Save your session and connect to the machine.
Create a Personal Access Token (PAT)
To install the build agent you need a Personal Access Token (PAT). Log in to you VSTS account and go to Security under your profile.
Click Add to create a new token. You can limit the access to read and manage Agent Queues.
Copy the token for later use.
Install the agent
To install the agent and all tools required for a typical agent (like npm, JRE, JDK etc.) we can use a shell script from github. Donovan Brown explained this in his blog.
Replace all values in {} with your data. Then just paste the entire command to putty and hit enter.
wget -O - https://raw.githubusercontent.com/DarqueWarrior/linuxSetup/master/linuxSetup.sh | bash && cd ~/Agents/a1 && ./config.sh --acceptteeeula --runasservice --url https://{YourAccount}.visualstudio.com --auth PAT --pool {AgentQueue} --token {YourToken} --agent {NameForAgent} --work _work && sudo ./svc.sh install && sudo ./svc.sh start
The command may run some time. After it completes your agent should be working.
If your done make sure to backup all files and information from docker-machine env {name}
. You will need this information to create a Docker Host Connection.