Quickstart - Deploy Docker container to container instance - Azure CLI - Azure Container Instances (2024)

  • Article

Use Azure Container Instances to run serverless Docker containers in Azure with simplicity and speed. Deploy an application to a container instance on-demand when you don't need a full container orchestration platform like Azure Kubernetes Service.

In this quickstart, you use the Azure CLI to deploy an isolated Docker container and make its application available with a fully qualified domain name (FQDN). A few seconds after you execute a single deployment command, you can browse to the application running in the container:

Quickstart - Deploy Docker container to container instance - Azure CLI - Azure Container Instances (1)

If you don't have an Azure subscription, create an Azure free account before you begin.

Prerequisites

  • This quickstart requires version 2.0.55 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.

    Warning

    Best practice: User’s credentials passed via command line interface (CLI) are stored as plain text in the backend. Storing credentials in plain text is a security risk; Microsoft advises customers to store user credentials in CLI environment variables to ensure they are encrypted/transformed when stored in the backend.

Create a resource group

Azure container instances, like all Azure resources, must be deployed into a resource group. Resource groups allow you to organize and manage related Azure resources.

First, create a resource group named myResourceGroup in the eastus location with the following az group create command:

az group create --name myResourceGroup --location eastus

Create a container

Now that you have a resource group, you can run a container in Azure. To create a container instance with the Azure CLI, provide a resource group name, container instance name, and Docker container image to the az container create command. In this quickstart, you use the public mcr.microsoft.com/azuredocs/aci-helloworld image. This image packages a small web app written in Node.js that serves a static HTML page.

You can expose your containers to the internet by specifying one or more ports to open, a DNS name label, or both. In this quickstart, you deploy a container with a DNS name label so that the web app is publicly reachable.

Execute a command similar to the following to start a container instance. Set a --dns-name-label value that's unique within the Azure region where you create the instance. If you receive a "DNS name label not available" error message, try a different DNS name label.

az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com/azuredocs/aci-helloworld --dns-name-label aci-demo --ports 80

Within a few seconds, you should get a response from the Azure CLI indicating the deployment completed. Check its status with the az container show command:

az container show --resource-group myResourceGroup --name mycontainer --query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table

When you run the command, the container's fully qualified domain name (FQDN) and its provisioning state are displayed.

FQDN ProvisioningState--------------------------------- -------------------aci-demo.eastus.azurecontainer.io Succeeded

If the container's ProvisioningState is Succeeded, go to its FQDN in your browser. If you see a web page similar to the following, congratulations! You successfully deployed an application running in a Docker container to Azure.

Quickstart - Deploy Docker container to container instance - Azure CLI - Azure Container Instances (3)

If at first the application isn't displayed, you might need to wait a few seconds while DNS propagates, then try refreshing your browser.

Pull the container logs

When you need to troubleshoot a container or the application it runs (or just see its output), start by viewing the container instance's logs.

Pull the container instance logs with the az container logs command:

az container logs --resource-group myResourceGroup --name mycontainer

The output displays the logs for the container, and should show the HTTP GET requests generated when you viewed the application in your browser.

listening on port 80::ffff:10.240.255.55 - - [21/Mar/2019:17:43:53 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"::ffff:10.240.255.55 - - [21/Mar/2019:17:44:36 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"::ffff:10.240.255.55 - - [21/Mar/2019:17:44:36 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"

Attach output streams

In addition to viewing the logs, you can attach your local standard out and standard error streams to that of the container.

First, execute the az container attach command to attach your local console to the container's output streams:

az container attach --resource-group myResourceGroup --name mycontainer

Once attached, refresh your browser a few times to generate some more output. When you're done, detach your console with Control+C. You should see output similar to the following sample:

Container 'mycontainer' is in state 'Running'...(count: 1) (last timestamp: 2019-03-21 17:27:20+00:00) pulling image "mcr.microsoft.com/azuredocs/aci-helloworld"(count: 1) (last timestamp: 2019-03-21 17:27:24+00:00) Successfully pulled image "mcr.microsoft.com/azuredocs/aci-helloworld"(count: 1) (last timestamp: 2019-03-21 17:27:27+00:00) Created container(count: 1) (last timestamp: 2019-03-21 17:27:27+00:00) Started containerStart streaming logs:listening on port 80::ffff:10.240.255.55 - - [21/Mar/2019:17:43:53 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"::ffff:10.240.255.55 - - [21/Mar/2019:17:44:36 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"::ffff:10.240.255.55 - - [21/Mar/2019:17:44:36 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"::ffff:10.240.255.55 - - [21/Mar/2019:17:47:01 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"::ffff:10.240.255.56 - - [21/Mar/2019:17:47:12 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"

Clean up resources

When you're done with the container, remove it using the az container delete command:

az container delete --resource-group myResourceGroup --name mycontainer

To verify that the container deleted, execute the az container list command:

az container list --resource-group myResourceGroup --output table

The mycontainer container shouldn't appear in the command's output. If you have no other containers in the resource group, no output is displayed.

If you're done with the myResourceGroup resource group and all the resources it contains, delete it with the az group delete command:

az group delete --name myResourceGroup

Next steps

In this quickstart, you created an Azure container instance by using a public Microsoft image. If you'd like to build a container image and deploy it from a private Azure container registry, continue to the Azure Container Instances tutorial.

Azure Container Instances tutorial

To try out options for running containers in an orchestration system on Azure, see the Azure Kubernetes Service (AKS) quickstarts.

Quickstart - Deploy Docker container to container instance - Azure CLI - Azure Container Instances (2024)
Top Articles
Vielfältige Anlagelösungen mit iShares ETFs | iShares DE - BlackRock
Term Life Insurance vs. Permanent Life Insurance - Oddball Wealth
Creepshotorg
Toa Guide Osrs
Cappacuolo Pronunciation
Star Sessions Imx
Collision Masters Fairbanks
The Potter Enterprise from Coudersport, Pennsylvania
Moviesda Dubbed Tamil Movies
MADRID BALANZA, MªJ., y VIZCAÍNO SÁNCHEZ, J., 2008, "Collares de época bizantina procedentes de la necrópolis oriental de Carthago Spartaria", Verdolay, nº10, p.173-196.
Roblox Character Added
Espn Expert Picks Week 2
Geometry Escape Challenge A Answer Key
Babyrainbow Private
WWE-Heldin Nikki A.S.H. verzückt Fans und Kollegen
Who called you from 6466062860 (+16466062860) ?
Les Schwab Product Code Lookup
Nene25 Sports
Tcu Jaggaer
Haunted Mansion Showtimes Near Millstone 14
Florida History: Jacksonville's role in the silent film industry
Gopher Hockey Forum
12 Top-Rated Things to Do in Muskegon, MI
Rimworld Prison Break
Engineering Beauties Chapter 1
The Boogeyman (Film, 2023) - MovieMeter.nl
Mta Bus Forums
UCLA Study Abroad | International Education Office
Scott Surratt Salary
Why comparing against exchange rates from Google is wrong
Rays Salary Cap
Wisconsin Volleyball Team Leaked Uncovered
Gina's Pizza Port Charlotte Fl
Autopsy, Grave Rating, and Corpse Guide in Graveyard Keeper
Japanese Pokémon Cards vs English Pokémon Cards
Navigating change - the workplace of tomorrow - key takeaways
Truckers Report Forums
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
Telegram update adds quote formatting and new linking options
Cherry Spa Madison
Cal Poly 2027 College Confidential
Omaha Steaks Lava Cake Microwave Instructions
Kent And Pelczar Obituaries
Lamont Mortuary Globe Az
QVC hosts Carolyn Gracie, Dan Hughes among 400 laid off by network's parent company
Thotsbook Com
5103 Liberty Ave, North Bergen, NJ 07047 - MLS 240018284 - Coldwell Banker
Is Chanel West Coast Pregnant Due Date
Convert Celsius to Kelvin
Elizabethtown Mesothelioma Legal Question
E. 81 St. Deli Menu
Emmi-Sellers
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated:

Views: 5372

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.