Setting Up Docker In Linux VM For Container Apps

Introduction

As the future is driving towards Cloud Native Applications, it is important to understand some of the basics of Containers and what container Apps are. Imagine, you are building an application for your company and your company CTO wants to run that application irrespective of the OS and it should be able to run in any Cloud Environment. In other words, the application should be able to run irrespective of its hosting environment, whether it could be on-premises environment or cloud. Let’s try to understand some of the basic terms of the Container World.

What is a Container?

A Container is a loosely isolated environment, that allows running your application irrespective of the computing environment.

After you develop, test and package your application, it should be running in any environment whether it is Linux, Windows, or Mac OS or any server environment, or in cloud environments such as Azure, Google Cloud, and Amazon. Almost all the industry cloud hosting environments support Container Apps.

To run the container apps, a run time must be provided just like you run a .NET App in your system it should have a .NET Run Time Environment. The Container Run Time is provided by Docker. There are other tools such as containerd, CRI-O, Mirantis Container Runtime. For the scope of this article, we will stick to the runtime provided by Docker.

What is Docker?

A docker is a containerized platform used to develop, build, and ship applications. Docker doesn’t use a hypervisor and you can run docker on your Desktop, Laptop while developing and testing the application.

In this article, we will do the following,

  • Setting up Linux VM using Azure Portal
  • Logging into Linux VM
  • Installing Docker
  • Validating the install

Please note that you need to have Azure Subscription to continue to the below steps. You can have your own subscription or the subscription given by your organization. Please refer to the references on setting up Azure Subscription.

Note
You can also set up docker desktop for windows. You can refer to the references section on how to set up a docker desktop on windows. This article focuses on setting up docker in Linux environment.

Setting up VM

Step 1

Login to the Azure Portal https://portal.azure.com and click on Create a Resource.

Setting Up Docker in Linux VM for Container Apps

Step 2

Click on the Virtual Machine.

Setting Up Docker in Linux VM for Container Apps

Step 3

In the next screen, enter the details in the 'Basics' Tab

  • Subscription: Select the subscription.
  • Resource Group: Create a new resource group or you can use existing one. For this scope, I created containerdev-rg
  • Virtual Machine Name: Enter any name. For this article, I am giving as azlinuxdevvm
  • Region: Chose the nearest region or leave default. Here I have chosen, east us.
  • Availability Zone: Leave the default
  • Security Type: Leave default, The default is ‘Standard’.
  • Image: Ubuntu Server 20.04 LTS – x64 Gen2
  • VM Architecture: Leave Default. The default is x64.
  • Run With Azure Spot Discount: Leave default. The default option is ‘No’.
  • Size: Leave Default. You can configure it if needed.
  • Authentication Type: Leave Default. The default option is ‘SSH Public Key’
  • Username: Leave Default. Please make a note of the user name.
  • SSH public key source: Leave default. The default option is ‘Generate new key pair’.
  • Key pair name: Please enter a name and make a note of it. For this case, I have entered as ‘containerdev23’.
  • Select inbound ports: Leave defaults. The default option is SSH(22).

You do not need to go to the next tabs, unless you need a specific setting. At the end click on ‘Review + Create’.

Setting Up Docker in Linux VM for Container Apps

Step 4

There is a basic validation process. If all the parameters are passed, you will get the below message saying validation passed. Click on create.

Step 5

Once you click on create, you will get a pop-up called 'Generate new key pair'. Click on 'Download private key and create resource'.

Setting Up Docker in Linux VM for Container Apps

Step 6

The key will be downloaded to 'Downloads' folder. Copy the key and put it in a location where you can easily refer for logging into Linux VM. In this case, I am keeping it under 'DeskTop\LinuxKey'.

Setting Up Docker in Linux VM for Container Apps

Step 7

Once the deployment of the VM is completed you will get the below message. Click on 'Go to resource'. Here you will see the status of the resource and it should be running.

Setting Up Docker in Linux VM for Container Apps

Setting Up Docker in Linux VM for Container Apps

The above steps conclude the creation of Linux.

Setting up Putty and PuttyGen

Please follow the below steps to set up Putty and PuttyGen as these tools are required to generate public and private key pair to login to Linux Environment. For the login we use putty. You can also use Bash from your windows terminal too.

Step 1

Download putty from the URL https://putty.org. From the home page, there is a link that downloads the package.

Setting Up Docker in Linux VM for Container Apps

Step 2

The link will take you to a list of packages. Chose the package that fit your OS needs. In this case, since I am installing it on Windows 11 machine, I am selecting 64-bit.

Setting Up Docker in Linux VM for Container Apps

Step 3

On clicking on the install link, it will download the MSI package to your downloads folder. Double-click the folder and follow the defaults.

Step 4

After installing the Putty, since the authentication to Linux is based on SSH private key (you can see the configuration from the section setting up Linux VM), we need following

  • Private key file for authentication: The certificate needs to be generated from the private key. To generate the certificate we need another tool called Putty Gen.
  • Certificate to use with private key: The private key is given by Azure while setting up the VM.

Putty Gen

PuttyGen is the tool to generate pairs of public and private SSH keys. Follow the below steps to generate a certificate based on the private key.

Step 1

Download the PuttyGen tool from URL https://www.puttygen.com

Step 2

From the home page, download the correct version. Since I am using windows 11 here I clicked on the link 'PuttyGen On Windows'.

Setting Up Docker in Linux VM for Container Apps

Step 3

From the download page, https://www.puttygen.com/download-putty scroll down to find the correct version. I have selected 64-bit puttygen.exe msi file.

Setting Up Docker in Linux VM for Container Apps

Step 4

The file 'PuttyGen.exe' should be available in the 'Downloads' folder. Click on the file

Setting Up Docker in Linux VM for Container Apps

Step 5

First, under the Parameters select the type of RSA to SSH-1 (RSA).

Setting Up Docker in Linux VM for Container Apps

Step 6

Click on the 'File -> Load Private Key'

Setting Up Docker in Linux VM for Container Apps

Step 6

Select the Private Key provided by Azure. Change the type of files at the bottom right corner to 'All Files'.

Setting Up Docker in Linux VM for Container Apps

Step 7

You would see a message saying that successfully imported a foreign key. Click on 'Ok'.

Setting Up Docker in Linux VM for Container Apps

Click on the option, 'Save private Key'.

Setting Up Docker in Linux VM for Container Apps

Step 8

You might be warned about saving the file without a passphrase. Select 'Ok'. For this article, we are not protecting the key with passphrase. In actual prod, it is recommended to protect the private key with a passphrase.

Setting Up Docker in Linux VM for Container Apps

Step 9

Give a meaningful name and click Ok. In this case, I gave as LinuxDevKeyLogin.

Now you have the required credentials to login to Linux VM, Open Putty, and then login.

Logging into Linux VM

Step 1

Since you have already installed Putty, now open the Putty App from the windows 11 machine.

Setting Up Docker in Linux VM for Container Apps

Step 2

Enter the host name of the Linux VM. In this case, it is 52.146.7.69. You can find the IP details from the Virtual Machine resources from the Azure portal.

Setting Up Docker in Linux VM for Container Apps

In the Putty app, click on 'Connection->SSH->Auth->Credentials'.

Setting Up Docker in Linux VM for Container Apps

Step 3

In the 'Private key file for authentication' select the file that is generated using PuttyGen. In this case, it is LinuxDevKeyLogin.

Setting Up Docker in Linux VM for Container Apps

Setting Up Docker in Linux VM for Container Apps

Step 4

In the 'certificate to use with private key' use the private certificate given by Azure while creating VM.

Setting Up Docker in Linux VM for Container Apps

Setting Up Docker in Linux VM for Container Apps

Step 5

Finally, click 'Open'. In the login as enter the user name. In this case, it is 'azureuser10'.

Step 6

If everything is correct, then you will get a welcome message. This confirms that login to Linux VM using putty is successful.

Setting Up Docker in Linux VM for Container Apps

Installing Docker

Follow the below steps to install the docker.

Step 1

First, check if the docker is already installed. You can find that by entering the below command.

Docker –version

Setting Up Docker in Linux VM for Container Apps

The message 'docker' not found confirms that the docker is not installed on the machine.

Step 2

Check the updates for the Linux system by entering the below command in the command shell.

Setting Up Docker in Linux VM for Container Apps

Step 3

The system gets the updates required and downloads them. Now enter the below command

Sudo apt install docker.io

Setting Up Docker in Linux VM for Container Apps

Step 4

It asks for disk space confirmation. Enter Y in the window.

Setting Up Docker in Linux VM for Container Apps

Step 5

After completion, it will be returned to the command window. Now check the installation by entering the command

docker --version

Setting Up Docker in Linux VM for Container Apps

Step 6

Run the sample container by entering the below command

sudo docker run hello-world

Setting Up Docker in Linux VM for Container Apps

If you see the message 'Hello from Docker' then all the setup required to run the docker images is successful.

Conclusion

Thus, in this article, we have seen a high-level introduction to containers, tools required to build the container apps, and setting up a development environment in Linux VM using docker. You can learn more about the containers from references section.

References


Similar Articles