Using docker compose in azure devops pipeline

In this blog post, I’ll show how to use docker-compose in azure DevOps pipeline for building and publishing your containers to ACR (azure container registry).
I am using an ASP.Net core project which uses SQL server as database. My asp.net core web application runs in one container and SQL server database is hosted in another container. Below is how the docker-compose file looks like.

image

This docker-compose YAML file is generated automatically as part of the asp.net core docker-compose project and is used to create required containers locally during development using docker desktop.

Similarly while deploying this to my azure environment I can use the same docker-compose file in docker-compose task in the azure pipeline to build and publish the image to ACR. Once the image is a container registry it can be deployed, for example, to an azure web app for containers. Below is how this sample YAML pipeline looks like.

ScreenClip

The first task is essentially a docker-compose build command and second task is a docker-compose push command.You can use these to push images to any of the existing container registry (need not to be only azure container registry) private or public.

Below is the screenshot for first docker-compose build task running. The yellow highlight shows the actual command that is run and the rest of the logs show how the dockerfile is used to build the image. Another interesting part is the text highlighted in orange which says “DB uses an image, skipping” which indicates an important point here that since for DB container we don’t build anything and just pull an image, there is nothing required to be done for DB. Which means that wherever the DB deployment is done we can directly pull that image from the public docker registry.

ScreenClip

In the end, the image which is built is tagged with azure container registry (i.e. myapp.azurecr.io/myap:latest) and in the next step, it will be pushed to the same.2nd step is shown below.

ScreenClip

This docker image will now be available in the Azure container registry.
To learn more on building deployment pipelines for asp.net core applications using docker refer to this pluralsight course.

One thought on “Using docker compose in azure devops pipeline

  1. n

    would you happen to know how to mount a volume (using a docker compose file) to one of the predefined variables of the pipeline? For example, if I wanted to mount a volume of the container’s “/output” directory to “$(Build.ArtifactStagingDirectory). i would think that’s possible…but don’t know how to do it

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.