Tea Time: Creating your CI pipeline for net core app container and AzureDevOps Part 3/4 – Building and Publishing Your Docker Image

In part 2, we added code analysis and tests tasks to the build pipeline, now it´s time to build the application and publish it to docker hub.

To build an Docker image, you need to create a Docker file and write the steps to mount your image. In the example, the Docker file is responsible for download the net core sdk image to build the image and download a net core runtime sdk to run the application within.

You can use your own Docker file or use the file from this repository as template.

Back to pipeline, add a new task, by clicking the + button on agent job. Search for Docker, select the Docker task and add to your pipeline. The default action will build the image and push to the container registry.

Once the task is placed, select a container registry connection, this is the place you will publish your image. The container registry can be a Docker Hub, Azure Container Registry or others. In this post we are using Docker Hub as container registry. For first time you need to add a connection to Docker Hub account Add a new connection and fill the properties of connection:

tea-time-creating-your-ci-pipeline-for-net-core-app-container-and-azuredevops-part-3-4-building-and-publishing-your-docker-image-01.png

On container repository property, write the name of image you want to create. The user account on Docker Hub must preeced the image name, otherwise, a access denied error will be thrown.

tea-time-creating-your-ci-pipeline-for-net-core-app-container-and-azuredevops-part-3-4-building-and-publishing-your-docker-image-02

When the pipeline runs, the Docker task will build the image based on the Dockerfile file and will publish the image to your Docker hub account. One important thing is the image tag, this property will set the image version of your Docker image. Change the default value $(Build.BuildId) to $(Build.BuildNumber) pipeline variable. This variable represents the build id number and is unique for each build.

Now your pipeline is ready to build your application and publish to the docker hub registry. In the next and final post we will add a final task, set the pipeline trigger and test it.

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