DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

jhaji12 for AWS Community Builders

Posted on • Updated on

Docker For Beginners

Small Story to Understand the use of Containers πŸ§™πŸ»β€β™€οΈ
"Let's meet our Characters first -

John (Software Developer)πŸ™‹πŸ»β€β™‚οΈ

Harry(Software Tester)πŸ‘¨πŸ»β€πŸ’Ό

John is a fresher and he is very excited to start his journey as a software developer. He is working on his first project which involves multiple languages, frameworks, and different libraries. According to his requirements, he use to install all the dependencies on his machine. πŸ‘¨πŸ»β€πŸ’»

Successfully, he was able to finish his project and it was running fine on his machine.

Next, he has to verify his project, so he sent the code to the testing team. Harry checked the code and It shows an 'Error ' ❌, but we know that the code runs fine on John's machine.

The problem comes with dependencies. All the dependencies that are used by John are different from what is being used by the tester which creates the problem. It can be due to the change in versions( for ex: John has used python 2.0 and the testing team is using python 3.0) or maybe there are some dependencies that John may not be knowing about and it is getting used in the app( Because that dependency was already installed in his machine). There are many reasons for the error that are not possible to detect again and again.

Now, we know that some dependencies or libraries are dependent on the Operating System as well, which may also be one of the reasons. It is not possible to transfer the OS itself to the testing team for John. πŸ€·πŸ»β€β™‚οΈ

Here, comes the role of Containers.

With the help of Containers, John can isolate his application from the environment, which solves the 'It works on my machine' problem. By this, his application can run quickly and reliably from one computing environment to another.

John gets appreciation from the manager, and he is very happy with his job and the team

πŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•ΊπŸ•Ί

What are Containers?

Creating a Docker container can be described as creating a small software package that can run a particular application and its associated processes.

The container that you create becomes portable and can be run on Docker installations on all types of computers in the same way without fear of compatibility issues.

What is the need for Containers if we have Virtual Machines?

Aβ€―Virtual Machine (VM) is a compute resource that uses software instead of a physical computer to run programs and deploy apps. One or more virtual β€œguest” machines run on a physical β€œhost” machine. Each virtual machine runs its own operating system and functions separately from the other VMs, even when they are all running on the same host. This means that, for example, a virtual Mac OS virtual machine can run on a physical PC.

There are disadvantages that became the reason for using Containers-

Running multiple virtual machines on one physical machine can result in unstable performance if infrastructure requirements are not met.
Virtual machines are less efficient and run slower than a full physical computer.
Whereas, Containers can be started much quicker than Virtual Machines. This is because the container is using the underlying host computer's Operating System, and not starting its own whenever it launches

What is a Docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.

Docker Architecture

Docker uses a client-server architecture. In simple words, Client communicates using REST API with daemon requesting for pull, build, run commands. Daemon accepts the commands and does the heavy lifting of building, running, and distributing your Docker containers. If a client is requesting to pull an image, then first it will communicate with daemon, and daemon will search for the image in local image registry, If not found then it will search it in Default Registry i.e Docker Hub and then the image will be sent to the client by daemon.

Docker Client -

When you use commands such as 'docker run', the client sends these commands to dockerd(Daemon), which carries them out. The docker command uses the Docker API to connect with daemon.

The Docker daemon

The Docker daemon (dockerd) listens for Docker API requests(from client) and manages Docker objects such as images, containers, networks, and volumes.

Docker registries

A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry.

Images

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the ubuntu image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.

You can understand it like this -

Image is a Class and Container is an object of the image

Where an object is an instance of class and class is a blue print of object.

-Jyoti Jha

Learning-> Teaching -> Enjoying :)

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.