Containers are pretty new in the Microsoft world, but are quickly getting traction. Microsoft Azure offers lots of container-related services such as Azure Container Instances (ACI), Azure Container Service (ACS), Azure Kubernetes Services (AKS) or Azure Container Registry (ACR). I already covered Azure Container Instances here, so I will not go into any details again – even if some things slightly changed since then. What I wanna cover in this post however is the automatic deployment of Docker images onto ACI.
I will cover and demonstrate, how to automatically deploy new ACI containers when a Docker image is pushed back to Docker Hub. This could be used as a simple release procedure to test new Docker images on Azure. For that, I will use Azure Logic App, a serverless component that allows me to design workflows. This workflow will be triggered directly from Docker Hub using a webhook. Let’s go.
Step 1 – Logic App
First, let’s create a new resource and select Logic App and give it an appropriate name. After a few seconds, the resource is provisioned and visible in the Logic Apps section.
Once created, I can now start creating my workflow. I am offered several templates that I can use as a starting point, but I will go for the blank one.
The workflow I will build here is very simple and only consists of 2 simple steps.
The first one is the trigger action and defines, how this workflow will be triggered. I use a HTTP request trigger which means, that I can use a web request to a specific URL to trigger the workflow. In this simple example, no more configuration is needed as I will not pass anything when triggering the workflow. The only thing I need to do here is memorizing the URL – or better copy it to the clipboard.
The second step actually does the work. Logic App has lots of connectors to Microsoft, Azure and many other services which gives you lots of flexibility. Here I use the “Create container group” action that allows me to deploy a new container in an ACI container group. I need to specify the resources I want to allocate to the container, specify the container group name, the container name and of course need to specify what image to use. This could be indeed more dynamic by passing the image name when the webhook is used, but for now we just keep it very simple. The image I use is on a public Docker repo. Because this is a very simple example, no more configuration steps are needed. But check out what can be configured when deploying the ACI container … there’s lots of stuff.
Now that’s it already. After saving the workflow, we can move to the next step which is the Docker Hub repo.
Step 2 – Docker Hub
I now connect up to my Docker repository and login. On the image of choice I navigate to “Webhooks” and will add the URI from my previously created Logic App HTTP request trigger.
That’s it, done!
Step 3 – Test
Now as everything is ready, it’s time to push my updated Docker image to Docker Hub using the Docker CLI.
On Docker Hub I can check if the web hook was triggered.
On the Logic App history, I can see that the workflow has been triggered and is running now. Depending on the exact workflow configuration, this may take a while.
Once the workflow completed successfully, the container group should be visible and contain the appropriate container based on my pushed Docker image. Again, this can take a while because the image will first be pulled from Docker Hub, which can take some time depending on the size of the image.
That’s it. Have fun building your own processes!
Cheers
Marcel
I have setup github actions to automatically create and image and push to ACR at the end of build process whenever a new commit added. But, how to add one more step to do autodeployment to azure container instances. Also, I used context option to have two containers interlinked.