Deploy Docker Containers in Azure App Service
Using tutorial from Mike Pfeiffer: https://mikepfeiffer.io/azure-docker-containers.html
DockerHub: https://hub.docker.com/r/rocker/shiny
Microsoft offers the Azure Container Registry (ACR), a managed Docker registry service (based on the open-source Docker Registry 2.0 platform).
- Provision a new ACR instance.
- Build a custom Docker image and push it to ACR
- With the image available in ACR, build a Web App resource that can host the application.
- Set up continuous deployment.
- Go to the "rocker/shiny" DockerHub page and run the provided docker pull command (need Docker installed locally): https://hub.docker.com/r/rocker/shiny
- Follow the tutorial here: https://mikepfeiffer.io/azure-docker-containers.html. Briefly,
- In Azure, Create Azure Container Registry (ACR) Resource. Fetch address and credentials in the "Access Keys" blade of the newly created Resource.
- From Command Line, authenticate to the Container Registry using the credential information.
docker login resourceName.azurecr.io
- From Command Line, edit the DockerFile as needed and build the Container image to push into Azure.
docker build -t <YOUR REGISTRY NAME>.azurecr.io/node-docker-demo:latest .
- From Command Line, push container to Azure
docker push <YOUR REGISTRY NAME>.azurecr.io/node-docker-demo:latest
- In Azure, go to the ACR resource > "Repositories" blade and verify that the image is uploaded.
- In Azure, build and deploy a web app resource using the image just uploaded to Azure.
- From your browser, access the website (e.g., https:// yourWebAppName.azurewebsites.net) to confirm that it's deployed.
- In Azure, go to the App Service resource > "Container Settings" blade, turn on Continuous Deployment. This automatically creates a webhook that will auto-deploy the container when it's updated in the Azure regstry.
- On local machine, make edit to the application code (an example update), rebuild the container image, push the image to Azure ACR (will update instead of create the image as long as you use the same name):
docker build -t <YOUR REGISTRY NAME>.azurecr.io/node-docker-demo:latest . #re-build after making edits to the code
docker push <YOUR REGISTRY NAME>.azurecr.io/node-docker-demo:latest #push to our ACR resource
According to Azure's pricing calculator, we save ~90% by switching to an App Service from a Virtual Machine ($73 vs $569 monthly), assuming the app service is performant.