Deploy a web app to Azure Container Registry and run it on Azure Container Instances

Tech Knowledge
Published on October 14, 2024

Premise knowledge

Azure Container Registry tasks streamline building, testing, pushing, and deploying images to Azure. For example, extend your inner development loop to the cloud by offloading Docker build operations to Azure using az acr build. Configure tasks to automatically rebuild application images when the base image is updated, or automate image builds when your team commits code to a Git repository. Create multi-step tasks to automate parallel execution of building, testing, and patching multiple container images in the cloud. Automate time-based tasks using task schedules.

※Offloading means "transferring (offloading) specific tasks or processes to other resources or devices."

Focus on application design and development by running your workloads on Azure Container Instances (ACI). You don't have to worry about managing the infrastructure that runs your applications.

Steps

1Create a Container Registry (Azure portal)

(1) Create

Home > Create a resource > Containers > Container Registry

  • Resource group: Select
  • Registry name: Arbitrary (alphanumeric only)
  • Location: Select a region
  • Pricing plan: Basic (default is Standard)

Click the "Review + create" button.

(2) Confirm username and password

Click the "Go to resource" button > Settings > Access keys
Check "Admin user" > The container registry username and password will be displayed.
Note down the registry name, login server, username, and password.

2Upload an image to Azure Container Registry (Command Prompt)

(1) Tag the image with the registry name.

docker tag イメージ名 レジストリ名.azurecr.io/イメージ名

Example)

docker tag reservationsystem:latest korochin.azurecr.io/reservationsystem:latest
docker images

C:\work\DockerSample\mslearn-hotel-reservation-system\src>docker images
REPOSITORY                               TAG       IMAGE ID       CREATED       SIZE
korochin.azurecr.io/reservationsystem    latest    69fcfb446922   4 hours ago   1.87GB
reservationsystem                        latest    69fcfb446922   4 hours ago   1.87GB

(2) Sign in to Azure Container Registry

Enter the container registry username and password.

docker login ログインサーバー

Example)

C:\work\DockerSample\mslearn-hotel-reservation-system\src>docker login korochin.azurecr.io
Username: korochin
Password:

Login Succeeded

(3) Upload the image to the registry in Azure Container Registry

docker push レジストリ.azurecr.io/イメージ名

Example)

C:\work\DockerSample\mslearn-hotel-reservation-system\src>docker push hoge.azurecr.io/reservationsystem:latest
The push refers to repository [hoge.azurecr.io/reservationsystem]
5f70bf18a086: Pushed
bd9055e56360: Pushed
9deed61a3a7d: Pushed
ed2725ff7639: Pushed
9b080d1e6444: Pushed
05e63465719b: Pushed
7a562491352c: Pushed
30722e965f80: Pushed
b668f0edb776: Pushed
bbf1566d0fe0: Pushed
99064051b3ca: Pushed
bee1e39d7c3a: Pushed
1f59a4b2e206: Pushed
0ca7f54856c0: Pushed
ebb9ae013834: Pushed
latest: digest: sha256:6002f5110b291746e24b77497f950e35b9aab0c5ac2d8a8da1a9708c073439bb size: 3675

3Check registry contents (Azure portal)

Container Registry service > Repositories
The uploaded image will appear in the list of repositories.

4Load and run an image using Azure Container Instances

(1) Create

Home > Create a resource > Containers > Container Instances

Basics tab
  • Resource group: Select
  • Container name: Arbitrary
  • Region: Select
  • SKU: Standard
  • Image source: Other registry
  • Image type: Private
  • Image: .azurecr.io/reservationsystem:latest
  • Image registry login server: <registry_name>.azurecr.io
  • Image registry username: Registry username
  • Image registry password: Registry password
Networking tab
  • Network type: Public (default value)
  • DNS name label: Arbitrary
  • DNS name label scope reuse: Tenant (default value)
  • Ports: 80 (default value)
  • Port protocol: TCP (default value)

※Note that if no value is set for "DNS name label", an FQDN will not be generated.

Advanced tab
  • Restart policy: Always
  • Environment variables: Default (blank)
  • Command override: Default ()

Click the "Review + create" button > Click the "Create" button.

(2) Confirm FQDN

Once the deployment is complete, click the "Go to resource" button. On the [Overview] pane, check the Fully Qualified Domain Name (FQDN) of the container instance. You will be able to access it via http://FQDN/.

Example)
http://FQDN/api/reservations/1