Azure Container Instances enables deployment of Docker containers onto Azure infrastructure without provisioning any virtual machines or adopting a higher-level service. Follow me on , happy to take your suggestions on topics or improvements /Chris Twitter The year was 1989. The game Zero Ving had just been released in Japan. Little did the creators of the game, Toaplan, know that their game would be legendary in 2019 for the screen you as a user was faced with when losing the game. — that is, you’ve lost. That’s of course not the case with containers, you are very much winning using containers and even more so when you bring them to the Cloud. All your base are belong to us It becomes more and more common today to develop as well as deliver your application in one or more containers. One of the most common containerization software’s out there is Docker. It’s a great tool making it very easy to create image as well as containers and also monitor the same. Wouldn’t it be great if we could continue using Docker and bring our app to the cloud In this article we will do the following: , why we might need the cloud Explain application source code from GitHub, let’s focus more on getting an application to the cloud rather than writing it from scratch, so let’s take an existing application Clone a container image from application source, this is a pre-step we need to do Create the image in a local Docker environment, it’s always a good practice to try out your software locally before we push it to the cloud Test a container registry, this is a thing on Azure that store Docker images Create our application, we can create a container instance from one of our images in the Container Registry Deploy Resources In case you missed the links we are mentioning in this article. Here they are: Installing Azure CLI The tutorial this article is based on az container command Learn module for Container Registry Docker tutorial series The promise of the cloud Using container technology allows us to split up our application into many services. On top of that, it offers a secure and reliable option to deliver the application. Now comes the next question, where do we deliver it to, On-premise or maybe to the Cloud? This article is about delivering your application to the Cloud so of course, we are a little bit biased. Let me explain in a few short points why we think the Cloud is a great place for your app: , it’s cost-effective in the sense that you only pay for what you actually use. In an On-Premise scenario, you might pay for servers, CPU, memory and so on for what you assume will be an increase in users and usage. That’s a lot of cash expenditure and you need to ask yourself do I want to spend the time to find out what I need and also spend time and money to upgrade it over time? Cost effective , The Cloud makes it possible to easily scale horizontally and vertically, adding a new worker, not a problem, adding more servers, databases again not a problem and something we can make happen in minutes Scalable , imagine you are an e-commerce company with sudden surges of users in the holidays or Black Friday and so on. The Cloud can dynamically add the extra resources you need to cope with that and of course, it can dynamically scale down when the number of users drops to a more normal rate Elastic Prerequisites You will need the following installed Docker, there are different guides here for Linux, Mac, and Windows, Check out the to see how to install Docker for your OS official docs Azure CLI install Clone the application We said initially we would focus more on how to deploy rather than write an application, so for that reason, we are going to use a pre-made application that you can pull down from here: git clone https://github.com/Azure-Samples/aci-helloworld.git Looking at it you can see that it is a very simple application running Express. There are two files of interest in the Repository for the sake of our demonstration: Node.js , this is the entry point to the application app/index.js , this is the Dockerfile that will help us build our application into an Image and finally will become a Container with the application within it. Dockerfile Let's have a look at the file: app/index.js const express = require('express'); const morgan = require('morgan'); const app = express(); app.use(morgan('combined')); app.get('/', (req, res) => { res.sendFile(__dirname + '/index.html') }); var listener = app.listen(process.env.PORT || 80, function() { console.log('listening on port ' + listener.address().port); }); Above we can see that it’s pretty standard application, no magic here. Node.js + Express Lets now have a look at the : Dockerfile FROM node:8.9.3-alpine RUN mkdir -p /usr/src/app COPY ./app/ /usr/src/app/ WORKDIR /usr/src/app RUN npm install CMD node /usr/src/app/index.js It does the following: , In short, we base the OS on Ubuntu and a release called alpine, that has Node.js pre-installed. Selects an OS image , with the following command Creates a directory mkdir -p /usr/src/app , from to Copies all the files ./app/ /usr/src/app/ , to Sets working directory /usr/src/app , using Installs our node dependencies npm install , using Starts our app node /usr/src/app/index.js All in all, this is a pretty standard looking . Dockerfile Build the image Building an image is pre-step we need to do before our application can actually be started. The build step will pull in the OS image we ask for, download dependent library, copy our app code in its place and so on. We can use the command to build an image. The exact command we will need to use is: docker build docker build ./aci-helloworld -t aci-tutorial-app The above command looks for the Dockerfile in the directory and creates an image called . Running the command should yield an output looking like this: /aci-helloworld aci-tutorial-app Above it’s showing us all the steps that we set up in the like: Dockerfile bringing down the OS image, copying our application node:8.9.3-alpine setting a , WORKDIR installing the dependencies by running , NPM INSTALL starting up the app with CMD node /user/scr/app/index.js We can see our created image if we run the following command: docker images Ok, then, we have an image which means we are ready for our next step; testing it locally. Test the image, by instantiating a container Now that we have an image, we can create a container from it, using . The full command looks like the following: docker run docker run -d -p 8080:80 aci-tutorial-app Let’s look at the arguments: , this tells the container to run in the background -d , this allows us to map ports, the argument value should be interpreted like this [external port]:[containers internal port] -p We can see that the external port is , which means we can navigate to 8080 http://localhost:8080 to ensure our application works. This is the image we get, so I would say our container is working: With the following command we can list all the running containers: docker ps It should present the following result: We don’t want a container running and using up resources so let’s shut it down. We want to run the command to shut down the container, however, that command needs an argument, it needs the . Remember when we run ? The first column was our . We don't need the full id though, it suffices with the 4 first characters. So let's kick off our command docker kill container id docker ps container id docker kill [container id, 4 first characters] docker ps // it should be an empty list That’s it. Here is a screen dump of the commands we just ran: Create a container registry Azure Container Registry is your private Docker registry in Azure. We need , and for this to work. We have already installed at this point so let's see how we can install : Docker Docker Engine Azure CLI Docker Azure CLI https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest Before we can create said registry we will need a . A is a logical container in which we need to place all our resources like applications, databases and now . Everything in the same group can easily and securely communicate. Resource Group Resource Group Resource Group so let’s create that first: az group create --name [your name for a resource group] --location westeurope Once this is created we can go back to creating our . Resource Group Container Registry The command looks like the following: az acr create --resource-group [your name for your resource group] --name [your name for a registry] --sku Basic --admin-enabled true Let’s break it down a bit. az acr create Is the actual command to create our . Then we need some arguments: Container Registry , this takes an argument that should be our newly created **--resource-group** Resource Group , this is the name we give our registry, e.g for example **--name** containerregistry , this is the price plan, we opt for the cheapest one called **--sku** Basic You should get an output looking like the following: { "adminUserEnabled": true, "creationDate": "2018-03-16T21:54:47.297875+00:00", "id": "/subscriptions/<Subscription ID>/resourceGroups/myResourceGroup/providers/Microsoft.ContainerRegistry/registries/mycontainerregistry082", "location": "eastus", "loginServer": "[your container registry name].azurecr.io", "name": "containerregistry", "provisioningState": "Succeeded", "resourceGroup": "myResourceGroup", "sku": { "name": "Basic", "tier": "Basic" }, "status": null, "storageAccount": null, "tags": {}, "type": "Microsoft.ContainerRegistry/registries" } The important part is getting a back with value . provisionState Succeeded Log in to our registry We need to log in to our registry before we can push docker images to it. So let’s log in: az acr login --name [name of container registry] That should tell you if all is well Login Succeeded Your output should look something like this: Above you can see that I opted to call the registry put you would have to replace that with your chosen name. chriscontainerregistry Tag container image To push a container image to a private registry like Azure Container Registry, you must first tag the image with the full name of the . registry's login server That’s something you can find out by looking at the JSON output when you created your registry. You are looking for a property called . It has the format of . In my case, that would be . "loginServer" [your registry name].azurecr.io chriscontainerregistry.azurecr.io So either you remember the name of , from when we created our container registry or you can always retrieve the later by calling this command: loginServer loginServer az acr show --name [container registry name] --query loginService --output table This will give us the name printed in our terminal. Of course would in our case be the value , so adjust accordingly depending on your chosen name. loginServer [container registry name] chriscontainerregistry Let’s now head back to Docker. We need to the image with the of your container registry. Tag aci-tutorial-app loginServer We tag it with the following command: docker tag aci-tutorial-app /aci-tutorial-app:v1 Let’s break it down. , this is the name of our image, run if you want to verify that aci-tutorial-app docker image , this will tag the image in way so it’s possible to push to our container registry. One note though, this is a version number but we can easily call this or today's date, the point is to have a system so you know if you want to use a specific image /aci-tutorial-app:v1 :v1 LATEST So the correct command in our case, using the correct values would be: docker tag aci-tutorial-app [container registry name].azurecr.io/aci-tutorial-app:v1 Run command at this point, to verify it was correctly created. It should look something like this: docker images Push the image to the repository Now we can actually push the image to the repository. We do so by executing the following command: docker push /aci-tutorial-app:v1 and with all the correct values in place, it would be: docker push chriscontainerregistry.azurecr.io/aci-tutorial-app:v1 You may need to log in first, in which case you run the following command: az acr login — name [container registry name] Carrying out the should render the following result: docker push List images in the repository Ok, so now we actually want to see what images we have in there, spoiler there should be the one we just uploaded ;) We can run the following command: az acr repository list --name --output table Using the correct value for it would look like this: acrName az acr repository list --name [name of container registry] --output table There it is, our only pushed image :) Deploy the application Now that we have our image in the repository, we can tell the repository to create a container from our image and thereby deploy our application. To run our deploy command we first need a little info, namely the following: login server, we can run the following command for that one az acr show --name --query loginServer username and password, for that we run this command: az acr credential show --name --query "passwords[0].value" This will return the password Ok, now we come to the deploy command, that might look a little bit intimidating: az container create --resource-group myResourceGroup --name aci-tutorial-app --image <acrLoginServer>/aci-tutorial-app:v1 --cpu 1 --memory 1 --registry-login-server <acrLoginServer> --registry-username <acrName> --registry-password <acrPassword> --dns-name-label <aciDnsLabel> --ports 80 There are a ton of ways to create a container, if you are interested in other ways, have a look at this link az container create Check progress and logs If it takes a while to deploy you can check status meanwhile, with this command: az container show --resource-group [name or resource group] --name aci-tutorial-app --query instanceView.state After a very long JSON response back, look for , if you have that you are good. provisioningState: Succeded Let’s have a look at our container with the following command: az container show --resource-group [name of resource group] --name aci-tutorial-app --query ipAddress.fqdn We can see the logs from the app by running: az container logs --resource-group [name of resource group] --name aci-tutorial-app This will tell us running on port 80 Visit the deployed app Once it’s deployed we can visit the app on the value, like so: --dns-name-label Summary We set out to deploy an app. This time we wanted to deploy a docker container. For that, we first needed to create a docker image. So we created one using . docker build Then we realized we needed an , cause it was from there we would deploy our image, i.e instantiate a docker container and deploy it. Container Registry To make it end up in the we first needed to tag it with the name, after that we pushed the tagged image. Container Registry loginServer Lastly, we told the to create a container from our image and deploy it. Once deployment was done we could go to our browser and verify the app was there, success :)) Container Registry It wasn’t that many steps really. I mean let’s say our app consisted of 3 other services. We would only need to build an image for each, tag it, push, and create a container.