Containers and Docker (Introduction)

In this blog, I am going to try to explain containers and docker in the simplest way possible.

Let's start,

So let's first talk about containers,

  1. Container.

    Before diving deep into containers we need to know the reason for using containers.

    Before the concept of containers, Virtual machines were used for using the memory or resources of the server better and also for running multiple applications at once on the same server.

Virtual Machines virtualize the hardware of the server, which means the VM has its resources, and dependencies but also OS.

VMs can run multiple operating system environments on a single physical computer, saving physical space, time and management costs.

Problem with VM:

  1. Memory Problem:

    As VM contains OS, the hardware of the server has to allocate separate memory for the OS which creates problems for running applications which need more memory that is left after allocating to the OS.

    Virtual machines can take up a lot of storage space. They can quickly grow to several gigabytes in size. This can lead to disk space shortage issues on the virtual machine's host machine.

  2. Sharing heavy VMs:

    Sharing the VMs is also a big problem as they are heavy and have so many things along with their OS bundled together.

  3. Iteration speed
    Virtual machines are time-consuming to build and regenerate because they encompass a full stack system. Any modifications to a virtual machine snapshot can take significant time to regenerate and validate they behave as expected.

    Solution: Containers

    Containers virtualize the OS + hardware for the applications to be run on the server.

    Thus they are lightweight and easy to install and share.


    Containers require fewer system resources than traditional or hardware virtual machine environments because they don't include operating system images
    .

    Containers are great for the development team and testing team to run and share the application.

From the above image, you can see the difference between VM virtualisation and Container virtualisation, if you are wondering what are hypervisor and container engine, don't worry we are going to cover them in the next blog, where we will discuss the working of the containers, VMs and docker.

  1. Docker

    Docker is a company which manages containers.

    you can call it a: (container management company or software)

    Now management means creating, storing, and running containers on systems.

Docker uses Docker Engine to manage containers on your system.

Images vs Containers:

1. Images:

Images are read-only templates containing instructions for creating a container.

2. Container:

Running image/Application over the system is the container.

Docker Architecture:

Docker has two main parts:

  1. Docker Engine

  2. Docker registry (Docker hub)

  1. Docker Engine:

    The Docker engine is responsible for managing, running, storing and creating containers and images on your system.

    The docker layer sits over the os to operate.

Docker engine has a client-server architecture, Docker engine has two main parts:

1. Docker CLI: It provides a platform to interact with docker daemon through commands with an API to perform certain tasks like creating containers, stopping them etc.

2. Docker Daemon: It is responsible for doing the main task. It controls or manages the containers and images on the system.

  1. Docker Registry (Docker Hub):

    Docker Hub is just like GitHub, it is the open place where you can make docker repositories, after creating your images you can add them to the docker hub to share with your teams.

Docker hub also has official images of other tech stacks like MongoDB,nginx etc which are created and managed by docker. inc, and you can pull those in your system to use them as containers.

Details about the working of VMs, Containers and Docker will be discussed in upcoming Blogs, So stay tuned!!

Bonus:

Can we run Linux docker images on windows or macOS?

Yes, Before it was not possible to directly run you needed some other solutions, but now docker has its Docker desktop by which there is no problem in running those images.