Azure DevOps: Deploying Docker Containers To Azure App Services Using YAML Pipelines
So, you've got a few Docker containers lying around and you're looking for a cheap, fast solution for deploying them. Azure App Services might be your answer. Microsoft offers very inexpensively licensing that ranges from free to highly scalable. Personally, I find app services great for low to medium-high traffic applications.
Deploying your Docker Containers is relatively simple too. There's a bit of configuration on the Azure side, but your deployments are a breeze.
Something I should note is that this is an example of the simplest possible workflow, your environment may not match exactly. If you have any questions about making this work for you, feel free to reach out!
Step 1: Getting Your App Service Ready
Let's walk you through how to set up an App Service that will consume a container to get you started. If you already have one good to go, feel free to skip to step 2.
Head to the Azure Portal
Search for "App Services" and head to the App Services page
In the upper left-hand corner, click "Create"
On the "Create Web App" page, enter your subscription, resource group, and name.
For Publish, choose "Docker Container"
For Operating System, choose "Linux"
Set the region & plan accordingly
8. Click Next : Docker >
9. You'll notice you have an option to change the container now. Leave it as-is.
10. Click Review + Create
11. Click Create
12. Save the name of the Resource Group, Name, and Region we'll need that in Step 3.
Step 2: Creating Your Azure Container Registry
Alright, you have your App Service ready to go. The next step is creating a place for you to publish your containers within Azure. To do that, let's walk through the steps to set up a new Azure Container Registry (ACR).
Search for container registry
Access the Container registries page in the Azure Portal
Click + Create
Fill in your resource group, registry name, and location
Save the name of the registry, we'll need it in Step 3
6. Click Review + Create
7. Click Create
Step 3: Putting Together Your Pipeline
So, you have your App Service, your Azure Container Registry is good to go. You're finally ready to push some code.
Now at first, it's going to seem like we're really not deploying anything, but hang tight until the last step.
Within your Azure DevOps tenant, head to Project Settings > Service Connections
Click New service connection in the upper left hand corner
Choose Docker Registry and click Next
Choose Azure Container Registry
Select the Subscription & Container Registry that you used in Step 2 to create your container
Now, head to your pipeline and add the Docker@2 task within your YAML pipeline (or classic!)
Add the following parameters:
tags: **YOUR TAGS**
containerRegistry: **NAME OF YOUR SERVICE CONNECTION**
repository: **REPOSITORY URL FROM STEP 2**
When you're done, your docker push task should look something like this:
- task: Docker@2 displayName: "Release: Push Docker Image to ACR" inputs: containerRegistry: ServiceConnectionName repository: yourrepo.azurecr.io command: push tags: latest
10. Run your pipeline and wait for it to finish.
11. Head back to your App Service in Azure and click Deployment Center
12. Click Container Registry at the top
13. Select your subscription, registry, and image tag
14. Click Save & You're done!
My Tag Isn't Showing Up in the "Tag" Dropdown within Azure Deployment Center
If your tag isn't being displayed, then more than likely, your container didn't get pushed in the pipeline. Double-check that your pipeline ran successfully in Step 3.10.
Also, head to your Azure Container registry and check to ensure that your container exists.