Docker Tutorial – Introduction To Docker; Containerization (4/9)

Tram Ho

1. Docker Instructions

This Docker Tutorial Blog will give you the concept and real-world exposure to Docker – A new era technology.

In this blog, we will focus on the following topics:

  • What is virtualization?
  • What is Containerization
  • Advantages of Containerization over Virtualization
  • Introducing Docker
  • Benefits of Docker
  • Virtualization vs. Containerization
  • Install Docker
  • Dockerfile, Docker Image & Docker Container
  • What is Docker Hub?
  • Docker architecture
  • Docker Compose

Simply put, Docker is a software container, which means you can build your applications, package them with their dependencies into a container, and then these containers can be easily Easy to transport to run on other machines.

For example, let’s take a look at a linux-based application that has been written in both Ruby and Python. This application requires a specific version of linux, Ruby, and Python. To avoid any version conflicts from the user side, it is possible to create a linux docker container with required versions of Ruby and Python installed with the application. Now end users can use the application easily by running this container without worrying about dependencies or any version conflicts.

These containers use Containerization which can be thought of as an evolved version of Virtualization. The same task can be achieved using Virtual Machines, but it is not very efficient.

I usually get one question at this point ie what is the difference between Virtualization and Containerization? These two terms are very similar. So let me first tell you what Virtualization is?

2. What is Virtualization?

Virtualization is a technique of importing the Guest operating system onto the Host operating system. This technique was originally a discovery because it allows developers to run multiple operating systems in different virtual machines, all running on the same server. This eliminates the need for additional hardware resources. The advantages of Virtual Machines or Virtualization are:

  • Multiple operating systems can run on the same machine
  • Easy maintenance and recovery in the event of faulty conditions
  • Total cost of ownership is also lower due to lower infrastructure needs

In the diagram below, you can see that there is a host operating system on which there are 3 guest operating systems running, nothing but virtual machines.

As you know nothing is perfect, Virtualization has some shortcomings as well. Running multiple Virtual Machines in the same host operating system leads to a decrease in performance. This is because the guest OS runs on the host operating system, which will have its own kernel and set of libraries and dependencies. This takes up a large amount of system resources i.e. hard disk, processor and especially RAM.

Another problem with Virtual Machines that use virtualization is that it takes almost a minute to start up. This is very important in the case of real-time applications.

Here are the disadvantages of Virtualization:

  • Running multiple Virtual Machines leads to unstable performance
  • The monitor is not as efficient as the host operating system
  • The start-up process is long and takes time

These limitations have led to the emergence of a new technique called Containerization. Now let me tell you about Containerization.

3. What is Containerization?

Containerization is a technique that brings virtualization to the operating system level. While Virtualization brings abstraction to the hardware, Containerization brings abstraction to the operating system. Note that Containerization is also a type of Virtualization. However, Containerization is more efficient because there is no guest operating system here and uses the host operating system, shared libraries, and associated resources when needed unlike virtual machines. Application-specific binaries and container libraries run on the server kernel, making processing and execution very fast. Even starting a container takes a fraction of a second. Because all containers share, host the operating system and keep only the binaries & libraries associated with the application. They are lighter and faster than Virtual Machines.

Advantages of Containerization over Virtualization:

  • Containers on the same kernel are lighter and smaller
  • Better resource usage than virtual machine
  • The boot-up process is short and takes a few seconds

In the diagram above, you can see that there is a server operating system shared by all containers. Containers only contain separate application specific libraries for each container and they are faster and not wasting any resources.

All of these containers are handled by the containerization layer that is not derived from the host operating system. Therefore, a piece of software is required that allows you to create and run containers on your host operating system.

4. Docker Instructions – Introduction to Docker

Docker is a containerization platform that wraps your application and all its dependencies together as a Container to ensure that your application works seamlessly in any environment.

As you can see in the diagram above, each application will run on a separate container and will have its own set of libraries and dependencies. This also ensures that there is process-level isolation, meaning each application is independent of others, giving developers the certainty that they can build applications that won’t. interfere with each other.

As a developer, I can create a container with different applications installed on it and give it to my QA team who will just need to run the container to recreate the developer environment.

5. Docker benefits

Now, the QA team doesn’t need to install all the dependent software and applications to test the code and this saves them a lot of time and energy. This also ensures that a consistent work environment between all the individuals involved in the process, starting from development to deployment. Number of systems can be easily expanded and code can be deployed on them easily.

6. Virtualization versus Containerization

Virtualization and Containerization both allow you to run multiple operating systems inside a server.

Virtualization involves creating multiple operating systems in a single server. On the other hand, Containerization will create multiple containers for every type of application required.

As we can see from the image, the main difference is that there are many Guest OSs in Virtualization that are not in Containerization. The best part about Containerization is that it is very lightweight compared to Virtualization.

7. Install Docker:

I will install Docker in my Ubuntu 17.10 machine. Here are the steps to install Docker:

  1. Install the Required Packages
  2. Set up a Docker repository
  3. Install Docker on Ubuntu

7.1. Install the required Packages:

There are certain packages you require in your system to install Docker. Execute the command below to install those packages.

sudo apt-get install curl apt-transport-https ca-certificates software-properties-common

7.2. Set up the Docker Repository:

Now, enter Dockers’ official GPG key to verify the package signature before installing them using apt-get. Run the following command on the terminal:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add

Now, add the Docker repository on your Ubuntu system where the Docker packages include its dependencies, to execute the command below:

sudo add-apt-repository “deb [arch = amd64] https://download.docker.com/linux/ubuntu $ (lsb_release -cs) stable”

7.3. Install Docker on Ubuntu:

Now you need to upgrade the apt index and install the Docker community version, to execute the commands below:

sudo apt-get update

sudo apt-get install docker-ce

Congratulations! You have installed Docker successfully. Also, take a look at some of the commonly used Docker Commands .

Let’s now take a look at a few important Docker concepts.

8. Dockerfile, Docker Image and Docker Container:

  1. The Docker Image is generated by a command string written in a file called Dockerfile.
  2. When this Dockerfile is executed using the docker command, it leads to a Docker Image and has a name.
  3. When this Image is executed with the “docker run” command, it will automatically start any application or service it has to start at execution.

9. Docker Hub:

Docker Hub is like GitHub for Docker Image. It’s basically a cloud registry where you can find Docker Image uploaded by different communities, you can also develop your own image and upload it on Docker Hub, but first, you need to create an account on DockerHub.

10. Docker architecture:

It consists of a Docker Engine which is a client-server application with three main components:

  1. A server is a type of long-running program called a daemon (docker command) process.
  2. A REST API specifies the interfaces programs can use to talk to the daemon and instruct it to do.
  3. Client command line interface (CLI) (docker command).
  4. CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the basic API and CLI.

11. Docker Compose:

Docker Compose is basically used to run multiple Docker Containers as a single server. I’ll give you an example:

Suppose if I have an application that requires WordPress, Maria DB and PHP MyAdmin. I could create a file that would boot both containers as a service without having to start each file separately. It’s really useful, especially if you have a microservice architecture.

Source: Edureka

Share the news now

Source : Viblo