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.
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.
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.
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.
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.
No comments:
Post a Comment