What Is Docker And How Does Docker Works?
Published: 2022-09-23 09:07:48

---
title: What Is Docker And How Does Docker Works?
published: true
date: 2022-09-19 10:22:00 UTC
tags: 
canonical_url: https://jainil.dev/what-is-docker-and-how-does-docker-works/
---



<div><button aria-expanded="false" aria-label="Expand Table of Contents"><span>Table of Contents</span><span></span></button></div>
<ul>
<li><a href="#before-containers">Before Containers</a></li>
<li><a href="#what-exactly-are-containers">What exactly are containers?</a></li>
<li><a href="#virtual-machines-vs-containers-vms">Virtual Machines vs. Containers (VMs)</a></li>
<li><a href="#then-what-is-docker">Then what is Docker?</a></li>
<li><a href="#why-should-you-use-docker">Why should you use Docker?</a></li>
<li>
<a href="#terminologies-used-by-docker">Terminologies Used by Docker</a><ul>
<li><a href="#docker-runtime">Docker Runtime</a></li>
<li><a href="#docker-client">Docker Client</a></li>
<li><a href="#docker-engine">Docker Engine</a></li>
<li><a href="#docker-daemon">Docker Daemon</a></li>
<li><a href="#docker-image">Docker Image</a></li>
<li><a href="#dockerfile">Dockerfile</a></li>
<li><a href="#docker-registries">Docker Registries</a></li>
</ul>
</li>
<li><a href="#introduction-to-our-docker-commands">Introduction to our Docker commands</a></li>
<li><a href="#installing-docker">Installing Docker</a></li>
</ul>
</div></nav>
## Before Containers

Let’s go back in time. Companies that wanted to run their applications back when computers were still novelties would have needed to purchase a server. The catch was that you could only run one application on each server. You would need to purchase numerous servers if you wanted to run multiple applications. This was a problem as costs would soar, affecting the business and the environment broadly.

By incorporating the idea of virtual machines into the game, IBM was able to resolve this problem. They allowed us to run numerous applications on a single server. You may have dual-booted your computer, installing Windows on a Mac or Ubuntu on a Windows computer. These machines are virtual ones. But they also faced a challenge. They required their own operating system, which tended to consume a significant amount of memory and disc space. They became inefficient and slow as a result.

Our Messiah Containers entered.

## What exactly are containers?

![What Is Docker And How Does Docker Works?](https://www.freecodecamp.org/news/content/images/size/w2000/2019/07/1_AUiK5PwnsPG_xaT9jcVoSA-2.jpeg)

Imagine relocating from India to Scotland. Would it be more convenient to ship your belongings one at a time or would you prefer to ship them all at once? Of course, the latter, isn’t it?

Simply put, that big box is a container.

Using the same analogy, suppose you created a website that functions flawlessly on your system but encounters issues when your friend tries to use it on their computer. We can use a container to ship the entire website along with all of its dependencies, including the web database, front end, back end, source code, etc., to avoid these hassles. This would guarantee that the website functions without a hitch on all devices.

Containerization is a productive way to run, deploy, and scale applications in the context of computing.


## Virtual Machines vs. Containers (VMs)

![What Is Docker And How Does Docker Works?](https://images.contentstack.io/v3/assets/blt300387d93dabf50e/bltb6200bc085503718/5e1f209a63d1b6503160c6d5/containers-vs-virtual-machines.jpg)

Any application that runs inside of a virtual machine needs a guest operating system, which calls for a hypervisor. On the host operating system, multiple machines are created using a hypervisor, which also controls the virtual machines. Every OS would need a specific amount of space in the hardware, which is practically divided, as you can see from the image.

With containers, you only need to have one operating system and an additional container engine, which is used to run applications. The concept of separating your application from the main operating system is used.

To put it simply, while containers use only the host operating system to run applications through the container engine, virtual machines use multiple operating systems to run multiple applications.

However, in practice, virtual machines run on top of containers. You could describe them as a lighter option.

## Then what is Docker?

One of the many container platforms is Docker, which enables you to create these containers to quickly and easily test, develop, and scale applications by running them in isolated environments.

This leads us to our following point.

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5629655985642576" crossorigin="anonymous"></script><!-- Post --><ins style="display:block" data-ad-client="ca-pub-5629655985642576" data-ad-slot="6912250213" data-ad-format="auto" data-full-width-responsive="true"></ins><script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
## Why should you use Docker?

- expedites the transfer of code
- facilitates application scaling, and deployment and issue identification
- save space because the entire application doesn’t have to be installed locally.

Let’s take a moment to become familiar with a few Docker terminologies that will simplify our lives.

## Terminologies Used by Docker

### Docker Runtime

We can start and stop containers thanks to it. The two are as follows:

- Low-level runtime (runc)
- High-level runtime (containerd)

### Docker Client

It enables users to give the Docker Daemon commands. Client-server architecture is utilised by Docker.

![What Is Docker And How Does Docker Works?](https://w3cschoool.com/public/file/Docker/docker-introduction.png)

### Docker Engine

It is in charge of ensuring that the Docker platform runs smoothly overall. It is a client-server application made up of three parts:

- Server – which runs the daemon
- Rest API – deals with the interaction of applications with their server
- Client – which is nothing but the command line interface (CLI)

### Docker Daemon

It is the central component of the Docker architecture and is responsible for creating, executing, and dispersing the containers. Additionally, it controls the containers and Docker images.

### Docker Image

The Docker image is the name of the file that houses the operating system files and source code needed to run the application and all of its dependencies inside the container. An application that has been containerized is an image’s active instance. Docker images cannot be changed.

### Dockerfile

It includes a list of guidelines for producing Docker images.

### Docker Registries

Images for Docker are kept in this location. The official online public repository for Docker, known as Docker Hub, is where you can find all the images of well-known programmes. We can also create our own images for our application using Docker Hub.

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5629655985642576" crossorigin="anonymous"></script><!-- Post --><ins style="display:block" data-ad-client="ca-pub-5629655985642576" data-ad-slot="6912250213" data-ad-format="auto" data-full-width-responsive="true"></ins><script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
## Introduction to our Docker commands

However, first…

## Installing Docker

To get started, you can consult the official documentation.

Visit Play With Docker, an engaging online playground for Docker, if you want to skip installation.

Back to some hands-on work now : )

```
docker run

```

![- Jainil Prajapati](https://cdn.hashnode.com/res/hashnode/image/upload/v1663394047807/MY8kGHTx8.avif?auto=compress,format&format=webp)

This command starts the container after creating it initially. It will first determine whether the most recent official image of hello-world is accessible on the Docker Host before creating the container (the local machine on which the docker engine is running). If not, as in the case mentioned above, the same will be downloaded automatically from Docker Hub before the container is created.

The container is created by running an image, and the image name in this case is _hello-world_.

```
docker images

```

This command displays a list of every Docker image available on the Docker Host.

![3qsYHqkWV - Jainil Prajapati](https://cdn.hashnode.com/res/hashnode/image/upload/v1663394248825/3qsYHqkWV.avif?auto=compress,format&format=webp)

Let’s explain each and every word that was used here:

1. REPOSITORY – This shows the name of the docker image.
2. TAG – This basically represents the version of the image being used. Each image has its own unique tag.
3. IMAGE ID – a string consisting of alphanumeric characters which are associated with every image.
4. CREATED – This depicts when the image was created
5. SIZE – This represents the size of the image

```
docker ps

```

It enables us to see each and every container that is active on the Docker Host.

![cOvJ8oS3G - Jainil Prajapati](https://cdn.hashnode.com/res/hashnode/image/upload/v1663394443138/cOvJ8oS3G.avif?auto=compress,format&format=webp)

```
docker inspect [image_name]

```

It provides details about the picture.

```
docker container prune -f

```

It will purge Docker of all stopped and inactive containers.

![- Jainil Prajapati](https://cdn.hashnode.com/res/hashnode/image/upload/v1663394622814/bO3w5Sx8G.avif?auto=compress,format&format=webp)

```
docker rmi [image_name]

```

It enables us to delete an image or images from the host.

![N4AUKmWbT - Jainil Prajapati](https://cdn.hashnode.com/res/hashnode/image/upload/v1663394712708/N4AUKmWbT.avif?auto=compress,format&format=webp)

We modify the RMI command in the following way to delete all the images at once:

```
docker rmi $(docker images -q)

```

![asbnblbef - Jainil Prajapati](https://cdn.hashnode.com/res/hashnode/image/upload/v1663394785039/asbnblbef.avif?auto=compress,format&format=webp)

I sincerely appreciate you reading this and spending the time that you did.