Deploy a multi-container group using Docker Compose
- Open Cloudshell
- Create a resource group with the az group create command. In the following example, a resource group named myResourceGroup is created in the eastus region:
az group create --name myResourceGroup --location eastus
- Once you’ve created the resource group, create an Azure container registry with the az acr create command. The container registry name must be unique within Azure, and contain 5-50 alphanumeric characters. Replace
<acrName>
with a unique name for your registry:az acr create --resource-group myResourceGroup --name <acrName> --sku Basic
- You must log in to your Azure Container Registry instance before pushing images to it. Use the az acr login command to complete the operation. You must provide the unique name you chose for the container registry when you created it.
az acr login --name <acrName>
- Get application code
git clone https://github.com/Azure-Samples/azure-voting-app-redis.git cd azure-voting-app-redis
- Modify Docker compose file
Open docker-compose.yaml in a text editor. The file configures theazure-vote-back
andazure-vote-front
services.version: '3' services: azure-vote-back: image: mcr.microsoft.com/oss/bitnami/redis:6.0.8 container_name: azure-vote-back environment: ALLOW_EMPTY_PASSWORD: "yes" ports: - "6379:6379" azure-vote-front: build: ./azure-vote image: mcr.microsoft.com/azuredocs/azure-vote-front:v1 container_name: azure-vote-front environment: REDIS: azure-vote-back ports: - "8080:80"
- In the
azure-vote-front
configuration, make the following two changes:- Update the
image
property in theazure-vote-front
service. Prefix the image name with the login server name of your Azure container registry, <acrName>.azurecr.io. For example, if your registry is named myregistry, the login server name is myregistry.azurecr.io (all lowercase), and the image property is thenmyregistry.azurecr.io/azure-vote-front
. - Change the
ports
mapping to80:80
. Save the file. - The updated file should look similar to the following:
version: '3' services: azure-vote-back: image: mcr.microsoft.com/oss/bitnami/redis:6.0.8 container_name: azure-vote-back environment: ALLOW_EMPTY_PASSWORD: "yes" ports: - "6379:6379" azure-vote-front: build: ./azure-vote image: myregistry.azurecr.io/azure-vote-front container_name: azure-vote-front environment: REDIS: azure-vote-back ports: - "80:80"
- Update the
- To deploy the application to Azure Container Instances, you need to push the azure-vote-front image to your container registry. Run docker-compose push to push the image:
docker-compose push
- To use Docker commands to run containers in Azure Container Instances, first log into Azure:
docker login azure
- Create an ACI context by running
docker context create aci
. This context associates Docker with an Azure subscription and resource group so you can create and manage container instances. For example, to create a context called myacicontext:docker context create aci myacicontext
- Next, change to the ACI context. Subsequent Docker commands run in this context.
docker context use myacicontext
- Run
docker compose up
to start the application in Azure Container Instances. Theazure-vote-front
image is pulled from your container registry and the container group is created in Azure Container Instances.docker compose up
- Run
docker ps
to see the running containers and the IP address assigned to the container group.docker ps
- To see the running application in the cloud, enter the displayed IP address in a local web browser. In this example, enter
52.179.23.131
. The sample application loads, as shown in the following example:
- When you finish trying the application, stop the application and containers with
docker compose down
:docker compose down
Tag:Azure