What is Docker Container, and how does it work ? (Part 1)

Dock Container? What it is?

Dock container is a self-contained sealed unit of software, this contains all the necessary resources to run the code and not more, this includes operating system and batteries. In other words, it contains all the codes, configuration and necessary processes within the container and the networking configuration to talk to the other containers that supposed to be talking but nothing else, additionally containers user the host machine kernel that is the main reason they can be very light and portable. All dependencies that your system needs are also added to the container. finally, it contains only the necessary components from the operating system to be able to run that code. Multiple containers can run on the same hardware, also maintains applications isolated, increase the productivity and the configuration is very quick and easy.  

How does it work?

For example, in a Linux server, it picks all the services from the Linux servers and copies all in the Linux kernel of each container, such as the codes, inter processes communication, networking, storage, etc. The containers live in their own world, they can't see other containers. It does not matter which operating system each service is running on, it just has to be a Linux distribution, therefore docker is the program that manages all these processes and integrates in one Linux Server, it sets it, monitors and delete it when they are no longer needed. 

Docker containers topology

What does it do?

What a docker does is split a computer into small containers with its own sealed world, with its own programs and everything is needed to run your specific code without any issue, all isolated from any other process or computer. The Docker container main goal is to be designed portable to get the code from one computer to another. The main advantage of this software is that it builds all these containers for you and because of its portability, this is a social platform so you can share your containers and find other containers that are different from your VMs, this is highly beneficial for you to find similar containers to work on top of them.

Hands on Dock Containers

Thing you should know before start learning about containers 

  • Experience using command line in any OS.
  • Essential networking knowledge.
  • Additional experience using shell scripting in Linux or bash is a plus.

Installation

Even though not everyone has Linux operating system installed in their devices, everyone can install any Linux server in a virtual machine leaving the host machine with any operating system, since docker needs a Linux server to administer, this would bring more flexibility in terms of choosing an operating system. Therefore, Docker will help running this Linux virtual machine. It is important to know that you can install docker in Windows, MacOS or Linux but you need a Linux server to be managed by Docker that can be ran virtually.

Now, this is how the installation works:

First, in your computer is where you will be typing on, then the interaction will be possible using the terminal in your computer, being this the client. Then this software is connected to the docker software that is the server controlling the installed virtual machine. Additionally, in the virtual machine you have the docker software installed. For checking if the program is running you should check on the whale icon, fortunately there is not much interaction with this other than start it or stop it since it is automated. Look at the picture below to have a better understanding.  

 

Installation topology

Steps to install Docker in a Windows Machine:

1.       Visit the official docker website at: https://www.docker.com/products/docker-desktop/ 

2.       Select the operating system in your host machine, then download it. 

 

3.       Install docker in your devise following the wizard.

4.       Check if docker in running by typing in your command line: docker run hello-world.

If you experience this error:


 Follow the next steps: 

1.       Enable windows subsystem for Linux by running this command in the PowerShell as an ADMINISTRATOR.

   dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart 

2.       Enable virtual machine feature by running this command in the PowerShell as an ADMINISTRATOR.

   dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

3.       Download and install the Linux kernel update package from this website: 

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi 

4.       Set WSL 2 as your default version by running this command in the PowerShell as an ADMINISTRATOR.

   wsl --set-default-version 2

Finally, when all the commands are executed, type in the command line again “Docker run hello-world”, and check if this everything is working correctly.


Steps to install Docker in a Linux Machine:

Installing Docker in Linux is much faster than other operating systems, you can install docker like you install any program on it.

Note: If you have installed previews docker versions, please remove all of them before you install the newest version.

1.       Make sure you have updated all dependencies in Linux typing:

   $ SUDO apt-get update

2.       Install all dependencies to allow apt to use repository over HTTPS:

  $ SUDO apt-get install  \

  ca-certificates   \

  curl    \

   gnupg  \

   lsb-release \

   apt-transport-https \

   software-properties-common 

3.       Tell your system to trust software provided by docker INC using a key that will be downloaded.

   $ SUDO curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

4.       Refresh dependencies again.

   $ SUDO apt-get update

5.       Now, install docker in your machine.

   $ SUDO apt-get install docker-ce

6.       Test if docker is running.

   $ SUDO run hello-world

 

Now that we are done with the boring stuff, let’s have some fun creating Docker containers by watching this video:

Learning the Basic on Docker Containers, Demo.


Conclusion

Docker is a relatively new revolutionary tool in the IT field, a tool well used IT professionals nowadays. This tool simplified the way to isolate processes and give them independency and most importantly improve the productivity and save resources in different organizations around the world, companies are moving from virtual machines to containerization to simplify their processes and use less resources. To better understand how it works I have created a docker flow picture that you can see bellow, everything starts with a base docker imagen then the imagen is run with docker, once the image is running we can make any modifications to the imagen, but they cannot be saved in the imagen file. After installing software, commands or any modification then you can save the docker container using the command “commit” to create a new image from the container modified. It doesn’t delete the container, the container stays there we just create an imagen with all necessary configurations. About the commands, “docker run” takes images to the containers and “docker commit” takes containers back to new images.

Docker Flow on how docker works.


Congratulations now you know the basics of Docker containers!! I hope you enjoy my content

 Thank you!

 Fernando Pina,

IT computer system student at SAIT. 

Comments