Build and push a Docker image

VSTS | TFS 2018 | TFS 2017.3


Build and release pipelines are called definitions in TFS 2018 and in older versions. Service connections are called service endpoints in TFS 2018 and in older versions.

This quickstart explains how to set up continuous integration (CI) to build a container image and push it to a Docker registry like Azure Container Registry or Docker Hub. At the end of this topic, you'll be ready to continuously deploy your image to a Kubernetes cluster or an Azure Web App for Containers.


Create an Azure Container Registry

You can use Azure Container Registry to host the Docker image that is published by the CI process. Follow the steps below to create and configure a registry. In later steps, you use VSTS to deploy the image to an Azure Web App for Containers.

  1. Sign into your Azure Account at

  2. In the Azure Portal, choose New, Containers, then choose Azure Container Registry.

  3. Enter a Registry name, Resource Group, and select a Location.

    Container Registry settings

  4. For Admin user, choose Enable and then choose Create.

  5. Wait for the Azure Container Registry deployment to finish.

Web or config as code

Do you want to define your build process in your web browser or configure it as code in YAML?


Choose this option if you prefer a graphical interface in your web browser.

PowerShell script task says "Hello World"

Adapt your CI pipeline

Here you'll adapt your CI pipeline so that it builds and pushes your container image.


Navigate to the Builds tab of the Build and Release hub in VSTS or TFS, and then edit your build pipeline. Select Tasks, and then add the following tasks:

icon Docker
  • Azure subscription: Select a connection from the list under Available Azure Service Connections or create a more restricted permissions connection to your Azure subscription. If you are using VSTS and if you see an Authorize button next to the input, click on it to authorize VSTS to connect to your Azure subscription. If you are using TFS or if you do not see the desired Azure subscription in the list of subscriptions, see Azure Resource Manager service connection to manually set up the connection.
  • Azure Container Registry: Select the Azure container registry that you created above.
  • Action: Build an image.
icon Docker
  • Azure subscription: Same as in the previous task.
  • Azure Container Registry: Same as in the previous task.
  • Action: Push an image.

Save and queue the build.

A new build is started. You'll see a link to the new build on the top of the page. Click the link to watch the new build as it happens. Verify that the Docker container image is built and pushed to your container registry.

Now your CI process is set up to push a new Docker image to a container registry every time a change is pushed to your application code.

Next steps