Docker Container Build Using Azure DevOps

Abstract Architecture
by Brad Jolicoeur

I have been working on expanding my knowledge on Docker Containers and wanted to understand how I could automate the build and deploy process of my website using VSTS which Microsoft recently re-branded as Azure DevOps. 

I have looked at VSTS for build and deploy in the past and found that it did not stack up to what TeamCity and Octopus Deploy offered as far as simple and straight forward configuration. While I could get things to work, it took a significant amount of effort and quite honestly a big reason I automate builds is so it I'm freed up to spend time working on things that add value.

I'm happy to say that things have gotten much better with Azure DevOps, and not just because the name changed. I was able to step through creating a container and pushing it to a container registry in about 10 minutes on the first try. 

Below are the steps I went through to create my build. This example is quite simple and does not include any environment variables or unit tests, but that makes it a good starting point. 


  • You already have an account on Azure DevOps (so recently known as VSTS)
  • You have a project established on Azure DevOps

Start by logging into Azure DevOps and Click on Build and release on menu bar.

Then select New > Build Pipeline to create a new build for your project.

In my case the project is on GitHub so I will select that as the repository source. The first time you do this it will ask you to authenticate with GitHub and then store your credentials. In this example I have already gone through that step and saved my credentials as the creatively named 'GitHub connection 1'. 

After you are authenticated with GitHub you can select your repository from the list and the default branch to build.

After clicking 'Continue' you will get a list of templates to select from. Since my website is in a Docker container, I will select the Docker Container template and click Apply.

After clicking Apply, you will have a newly created build pipeline that is ready to be configured. 

The first thing to configure will be the Agent Pool. In this example I'm building a project into a docker container so I will select 'Hosted Linux Preview'. On my first attempt I selected the 'Hosted' Agent pool which does not have docker installed and my builds failed. Once you have this mastered, you will probably want to create a private Agent for Docker builds so the layers can be cached. The Hosted agents need to pull the layers for each build so they will take 5 to 6 minutes for each build. 

The next thing to configure will be the 'Build and image' step. You will need to set the container registry for images needed for the build and specify the docker file path. 

Next you will need to configure the container registry you are going to push your image to in the 'Push and image' build step.

You can now click 'Save & Queue' button above the build steps. This will display a dialog where you can add a comment and make changes to the pool and branch for this specific build run. For this example leave the values and click Save & queue. 

The build will kick off at that point and you will be able to see where the build is in the process. 

Again, since the agent is hosted and we are doing a docker build, it will take several minutes to download all of the required layers and execute the build. 

If everything goes well you will get a success message like this one.

If things do not go well, you will get a detailed error message that will not look super detailed at first. When you click the error block, the details will come up in a dialog. In this case I forgot to specify my docker file.

Once I clicked on the error message, the details below were displayed and I was able to quickly figure out why my build failed.

I hope you found this example helpful. My next step will be to figure out how/if I can use Azure DevOps to deploy my Docker container to my AWS Lightsail server.