Quickstart: Deploy a container instance in Azure using the Docker CLI
Use Azure Container Instances to run serverless Docker containers in Azure with simplicity and speed. Deploy to a container instance on-demand when you develop cloud-native apps and you want to switch seamlessly from local development to cloud deployment.
In this quickstart, you use native Docker CLI commands to deploy a Docker container and make its application available in Azure Container Instances. This capability is enabled by integration between Docker and Azure. A few seconds after you execute a
docker run command, you can browse to the application running in the container:
If you don't have an Azure subscription, create a free account before you begin.
Not all features of Azure Container Instances are supported. Provide feedback about the Docker-Azure integration by creating an issue in the aci-integration-beta GitHub repository.
Create Azure context
To use Docker commands to run containers in Azure Container Instances, first log into Azure:
docker login azure
When prompted, enter or select your Azure credentials.
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
When prompted, select your Azure subscription ID, then select an existing resource group or create a new resource group. If you choose a new resource group, it's created with a system-generated name. 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.
docker context ls to confirm that you added the ACI context to your Docker contexts:
docker context ls
Create a container
After creating a Docker context, you can create a container in Azure. 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.
First, change to the ACI context. All subsequent Docker commands run in this context.
docker context use myacicontext
Run the following
docker run command to create the Azure container instance with port 80 exposed to the internet:
docker run -p 80:80 mcr.microsoft.com/azuredocs/aci-helloworld
Sample output for a successful deployment:
[+] Running 2/2 ⠿ hungry-kirch Created 5.1s ⠿ single--container--aci Done 11.3s hungry-kirch
docker ps to get details about the running container, including the public IP address:
Sample output shows a public IP address, in this case 188.8.131.52:
CONTAINER ID IMAGE COMMAND STATUS PORTS hungry-kirch mcr.microsoft.com/azuredocs/aci-helloworld Running 184.108.40.206:80->80/tcp
Now go to the IP address in your browser. If you see a web page similar to the following, congratulations! You've successfully deployed an application running in a Docker container to Azure.
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.
For example, run the
docker logs command to see the logs of the hungry-kirch container in the ACI context:
docker logs hungry-kirch
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 - - [07/Jul/2020: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 - - [07/Jul/2020: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 - - [07/Jul/2020: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"
Clean up resources
When you're done with the container, run
docker rm to remove it. This command stops and deletes the Azure container instance.
docker rm hungry-kirch
In this quickstart, you created an Azure container instance from a public image by using integration between Docker and Azure. Learn more about integration scenarios in the Docker documentation.
You can also use the Docker extension for Visual Studio Code for an integrated experience to develop, run, and manage containers, images, and contexts.
If you'd like to use Docker Compose to define and run a multi-container application locally and then switch to Azure Container Instances, continue to the tutorial.
Submit and view feedback for