The Problem
I wanted to start using Docker Containers on Azure as I had been using them locally for ages and found them very useful. I had progressed to using Docker Compose for multi-container apps and even for single-container apps as the compose-file contained all the information needed to run the container rather than remember port-mappings, volumes etc for the docker run command.
However….the documentation for containers on Azure is confusing. It’s simple to get a container up and running but it’s not so simple to understand what/where/why. Hence this article
The problem is compounded by there being many ways to do the same thing (a common MS theme) so it is possible to run Docker containers from the Docker CLI, they can also be run from the Azure CLI (an installable add-in) and can also be configured and run from the Azure Portal web-interface.
In addition, there are “different” ways to run Docker containers within Azure itself, they can be run as part of “App Services” as a Web-Application (see below) or can be run as an Azure Container Instance (ACI).
And…to complicate matters, Docker Compose from the Docker CLI was supported although that support was removed in December 2023. And (2)……Docker Compose multiple containers are tricky to run in any event as “App Services Web Applications” do not support port-mapping and only expose ports 80 and 443, so, if you have, say, a web front-end and webapi in the same Compose file using ports 8080 and 8082 you are stuffed.
Confused. Well I was and hopefully this article will make you less so
TLDR;
In case you don’t want to read the below
- Watch An Introduction to Containers in Azure
- Read Deploying containers from the Docker CLI, it does what it says on the tin
- Read Deploying containers from the Azure CLI. It does what it says on the tin
- Read Deploying Multi-conainers using Docker Compose and this Tutorial. They does what it says on the tin. Unfortunately, Docker no longer supports Compose with Azure
- Read Container Groups in Azure and Deployinga multi-container group using a YAML File for an alternative to Docker Compose. NB I haven’t worked out how to do this yet
Useful information
- Docker Compose from Docker CLI no longer supported
- “Web Apps” do not support port-mapping. They only expose ports 80 and 443 – this makes multi-container apps exposing enpoints almost impossible in one Compose file.
- Azure Container Instances support port mapping
ToDo (for me, then I’ll update this article)
- YAML multi-container deployment and port mapping(s).
- Kubernetes deployment
- Where there is a supported way to deploy Docker Compose with multiple endpoints
Docker CLI
Docker Context
First read Deploying containers from the Docker CLI
Using Azure from the Docker CLI requires a “Docker Context” be set up which contains all the details for Azure. The context can be “used” and the the user can return to the local “default” context
docker context list NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR default moby Current DOCKER_HOST based configuration npipe:////./pipe/docker_engine desktop-linux moby Docker Desktop npipe:////./pipe/dockerDesktopLinuxEngine myacicontext * aci myresourcegroup # Use Azure docker context use myacicontext docker run -p 80:80 mcr.microsoft.com/azuredocs/aci-helloworld # Use local docker docker context use default
Single Containers
First read Deploying containers from the Docker CLI
docker context use myacicontext docker run -p 80:80 mcr.microsoft.com/azuredocs/aci-helloworld
This runs the container as an Azure Container Instance (ACI). Port remapping cannot be done but port-numbers can be exposed.
Compose Files
First Read Deploying Multi-conainers using Docker Compose and this Tutorial
docker context use myacicontext docker compose up
This creates and Azure App Services WebApp. Port remapping cannot be done. The Webapp exposes only ports 80 and 443 (I believed mapped internally to 80 and 443). A compose file cotnaining multiple containers exposing multiple endpoints will be tricky to get working (i.e. it won’t work I think)
Azure CLI
Running a Container
FirstRead Deploying containers from the Azure CLI
Create an Azure Resource Group
az group create --name myResourceGroup --location uksouth
Run the container
az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com/azuredocs/aci-helloworld --dns-name-label aci-demo --ports 8000
This creates an Azure Container Instance (ACI) and exposes port 8000 (port remapping is not supported).
Compose FIle
First read Deploying Multi-conainers using Docker Compose and this Tutorial.
Create an Azure Resource Group
az group create --name myResourceGroup --location uksouth
Create an App Service Plan (this examples uses linux). The “sku” I think can be set to F1 (i.e. free service)
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku S1 --is-linux
Create webapp with the compose file as the “source” (example taken from MS uses WordPress)
az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app-name> --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml
This creates an Azure App Services WebApp. Port remapping is not supported. Only ports 80 and 443 are exposed.
Azure Portal Interface
TBA
Summary
Method | Command | Creates | Notes |
Docker cli | docker run | ACI | No port mapping, multiple ports can be exposed |
Docker cli docker compose | docker compose up | Azure WebApp | No port mapping, only ports 80,443 exposed |
Azure cli (container) | az container create | ACI | No port mapping, multiple ports can be exposed |
Azure cli (compose) | az webapp create | WebApp | No port mapping, only ports 80,443 exposed |
Docker CLI and Compose Information Message
From the Docker CLI when using a Docker Context for Azure and you do
docker compose up
You get the following message
Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/
What that means, I think, is that Docker have stopped supported Compose from the Docker CLI. I’m not sure if you can use/is-supported Docker Compose from the azure CLI