Docker In Production

In this post, we will see the simplest example of running containerized Applications in production. For running a real-world containerized business Application in production environment, we usually take into account stuff such as cluster management with DC\OS or Docker Swarm, use the containers specific services like EC2 Container Service, Azure Container Service, DigitalOcean and other factors. Here, we will see, how we run one container in a simple production environment, which is a Linux Azure VM (An Azure service specifically configured for running Docker containers named Docker on Ubuntu Server) in Microsoft Azure. Although there are other vendors too who provide the Services for running the containers, we will consider Microsoft Azure throughout our series, which will be the basis of our next steps i.e. running complex microservice, based on the Applications in Cloud.

Microsoft Azure Services for containers

Primarily, there are 2 Azure Services available for running containers, which are-

  • Docker Ubuntu Server
  • Azure Container Service

We will see here the first one for the sake of simplicity. Azure Container Services are pre-configured, best-practiced and secured VM's for running containers Workloads. We can use either DC\OS or Swarm for orchestrating containers across the different nodes. Docker on Ubuntu Server is a small Linux VM Azure Service, which has enough capability to run a Docker Host, which comes with it as a VM extension. We cannot use remote-client connections to interact with this VM, as we used to do in a normal Azure VM.

Creating a Docker Ubuntu VM

To create the Service, open-up your Azure portal and go to-

New > Containers > Docker on Ubuntu Server


Click create and in the new blade, which popped up, enter your Host Name, a user name with a password. You can also use public and private SSH keys here, instead of a password. We'll name our Host Name as janshair, as shown below-



Fill-out other attributes to create the Service, click create and you will see that Azure starts creating VM for you.

After a while, when the VM is ready, configure the end-points of this VM to port 80 for both public and private ports by going to-

VM > Settings > EndPoints > Add


In Add blade, type the name as Docker (Or any other name you want), assign the port number 80 to both public and private ports, leave everything else the same, click OK and you will see the configured end-points for your Ubuntu VM, as shown below-



We are assigning the number 80 to both the public and private ports because we will be exposing our Application from the container to this port number due to which we can see it at the default port in our client Browser.

Now, our VM is ready. Next, we SSH into this VM, using an SSH client. We'll be using PuTTY, but you can use any other SSH client, which you want. Open-up PuTTY and type the host name and port number (SSH Port 22 by default, as shown above) of the VM, which is configured for us. Here, we will enter janshair.cloudapp.net with the port number 22, as shown below-



It may display a warning while activating SSH into a machine for the first time. In this case, just click Yes.

After clicking Open, it will ask for the user name and password that we configured while creating the VM. Enter the user name and password and then we see that we are successfully logged-in in our Ubuntu VM running in Azure, as shown below-



Now, we are in an Ubuntu machine, where Docker is up and running. You can check Docker version, installed in the VM as-

docker --version

Currently, there will be no Docker image available here. You have to download a Docker image from Docker Hub. You can either pull down your own Docker image, if you have any, or use an image, which has been pushed to Docker Hub. Thus, I'm going to pull my own image as,

docker pull kjanshair/aspnetcore-example:latest

After a while, when the image is downloaded, simply run the command, given below, to expose the port 5000 from the container to the port 80 on the host machine by typing in the terminal as-

docker run -p 80:5000 kjanshair/aspnetcore-example

Now, navigate to http://janshair.cloudapp.net in the Browser. We see that our container is up and running in an Azure VM Service for Docker in Cloud, as shown below-


Here, we just saw, how to run a container in Microsoft Azure for the production use. In a real world Applications, we usually don't use one VM with one Docker Host and one container. For Applications like these, it usually contains the specific Services like Azure Container Service or EC 2 Container Service with a cluster manager like Docker Swarm, Kubernetes, DC\OS and others.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now