Connect Azure container instance(ACI) using docker-compose CLI

By using cloud platforms, we can take advantage of different resource configurations and compute capacities. However, deploying containerized applications on cloud platforms is proving to be quite challenging, especially for new users who have no expertise on how to use that platform. As each platform may provide specific APIs, orchestrating the deployment of a containerized application can become a hassle.

In this blog post, we discuss how to use Docker Compose to deploy containerized applications to Azure container instances. We aim to show how the transition from deploying to a local Docker environment to deploying to ACI is effortless, the application being managed in the same way for both environments.

Requirements

In order to exercise the examples in this blog post, the following tools need to be installed locally:

$ curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh

Throughout this blog post, we discuss how to:

  1. Create an ACI context to target Azure container instances.
  2. Run the Compose application on the Azure container instance from ECR.

Create an ACI context to target Azure container instances.

To make Docker Compose target the Azure container platform, we need first to create a Docker context of the ACI type. A docker context is a mechanism that allows redirecting commands to different Docker hosts or cloud platforms.

We assume at this point that we have AWS credentials set up in the local environment for authenticating with the ECR platform and we have an azure credential

To create an ACI context we need to first give access to docker to connect with azure, Run the below command to authenticate to Azure with the portal.

$ docker login azure

Once authenticated we need to create an ACI context.

$ docker context create aci myacicontext
Successfully created aci context "myacicontext"

The current context in use is marked by * in the output of context listing:

$ docker context ls
NAME                TYPE      DESCRIPTION                                   DOCKER ENDPOINT       default *           moby      Current DOCKER_HOST based configuration       unix:///var/run/docker.sock

myacicontext        aci                                                                  

To make all subsequent commands target Azure ACI, make the newly created ACI context the one in use by running:

$ docker context use myacicontext
myecscontext


$ docker context ls
NAME                TYPE         DESCRIPTION                               DOCKER ENDPOINT              
default             moby         Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
myacicontext*        aci                                                                  

The sample docker file with three containers with shared file volume

$ cat docker-compose.yaml
services:
  nginx:
    image: nginx
    ports:
      - "80:80"
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: example
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080  
  volumes:
      - mydata:/mount/testvolumes

volumes:
  mydata:
    driver: azure_file
    driver_opts:
      share_name: tempdir
      storage_account_name: sample_account_name
      
                  

The above

`sample_account_name` -> is a azure storage name

`tempdir` -> is a azure file name

Please create that storage manually and add the respective name.

Then deploy the dockers compose applications to ACI, we can run the same command as in the local deployment:

$ docker compose up -d --project-name demo

Run the Compose application on the Azure container instance from ECR.

For deploying the application from ECR we need to login into the respectively

$ docker context use myacicontext
myecscontext

$ aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin <aws_account_id>.ABC.ecr.us-east-2.amazonaws.com

The sample docker file with ECR image.

$ cat docker-compose.yaml
services:
  nginx:
    image: <aws_account_id>.ABC.ecr.us-east-2.amazonaws.com/nginx
    ports:
      - "80:80"

Then deploy the docker-compose applications to ACI, we can run the same command as before:

$ docker compose up -d --project-name ecr-aci-demo

Challenges in ACI

  • Memory is limited to 16GB
  • CPU is limited to 4
  • The disk is limited to 20 to 50GB

Categorized in:

Tagged in:

,