# Docker : The Dev Container

## What is Docker?

Docker is a containerization platform that packages applications into containers to run without any problem.

## Before Docker/Containerization tool?

Before this for every application we use one whole server , which is so costly and difficult to maintain ,  
so VMware solved that problem by using Virtual machines .

Even in Virtual Machines there are many flaws like,

* Dedicated OS for each application
    
* Not fast enough
    
* Dedicated storage
    
* Dedicated hardware & so on…..
    

Before Tools like Docker used in market , we have a Problem “**IT works on my machine“.**

Docker solved All the Problems.

## Containers

Containers are collection of thing we need to run our applications.

It contains

* Base OS (mostly light weight OS)
    
* Infrastructure
    
* Container Engine
    
* Libraries needed to run the application
    
* Applications
    

### Virtual Machines VS Containers

In Virtual Machines we need multiple OS to run multiple Application  
But In Containers we just one OS for multiple Applications .

We use Container engine to run Multiple apps in single OS.

![Docker Vs Virtual Machines](https://media.licdn.com/dms/image/v2/D4D12AQGqjSqEGElq1w/article-inline_image-shrink_1500_2232/article-inline_image-shrink_1500_2232/0/1688608296456?e=1752710400&v=beta&t=LohT337kT0HigtTGslyPDKnPU6bnEBAb_AgclyReDAk align="left")

## Installation

### Windows

Install Docker Desktop + WSL from ( [Windows OS](https://docs.docker.com/desktop/setup/install/windows-install/) ).

### Mac

Install Docker Desktop from ( [Mac OS](https://docs.docker.com/desktop/setup/install/mac-install/) ).

### Linux

Install Docker Engine not Docker Desktop from ( [Linux](https://docs.docker.com/desktop/setup/install/linux/) ).

## Parts of Docker Desktop / Docker

Docker Runtime.

Docker Engine.

Docker Orchestration.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1747852468595/f6191220-12ba-4175-9a1f-bd0a0280876d.png align="left")

## Docker Runtime

Basically allow us to Start/stop the container.

* runC (low level).
    
* containerD.
    
    * getting Data /internet.
        
    * manage runC.
        

## Docker Engine

It contains Docker CLI , Rest API , DockerD(server) , Daemon .

Rest api is used to bridge between Sever and CLI .

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1747853086674/ada005e9-d758-4844-a4af-3fa11eecd1ee.png align="left")

## Docker Orchestration

This manages the Containers .

Kubernetes is one of the orchestration tool.

## Docker Images

Its a file that contains all the instructions to create a container for our applications.

We can Create Docker Images using Dockerfile.  
We can Create Container using Docker Image.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1747853871701/1374f6dc-5ad5-4bbc-8cec-3da9ada50266.jpeg align="center")

## Docker CLI commands

```powershell
// docker run image-name
docker run hello-world
```

<mark>docker run</mark> - it will run the docker image if it is locally available or its download it from Docker Hub

```powershell
docker images
```

<mark>docker images</mark> - it will return the available images locally

```powershell
// docker pull image-name
docker pull ubuntu
//docker pull image-name:tag/version
docker pull ubuntu:16.01
```

<mark>docker pull</mark> - it will download the image from the Docker Hub  
**Note : if tag is not defined it will automatically download latest version**

```powershell
docker run -it ubunut
```

docker run <mark>-it</mark> ubuntu - its runs the image in interactive environment

```powershell
docker ps
docker container ls
```

return all running containers

```powershell
docker ps -a
```

return all the stopped containers

```powershell
//docker rm container-id
docker rm 4f2304iua402j
```

<mark>docker rm</mark> - it will remove/delete the container

```powershell
//docker rmi image-id
docker rmi 4239u020jasf9
```

<mark>docker rmi </mark> \- it remove the docker image

## Docker Layers

A Docker image is collection many files/layers

Each layers have a unique hash values as ID using “SHA256” representation.

If Two Docker images have same layer/file it will not download again from Docker Hub. it will use the already installed one for both images.

## How to Create a Docker Image?

1. create a file named “ **Dockerfile** “ in the requires directory/folder.
    
2. write create instruction to run the container using Linux cmd’s.
    
3. Must declare a Base image(OS) in the file.
    
4. Write the instructions need to run the applications.
    
5. save the file.
    

```powershell
//docker build -t image:tag/version path
docker build -t test-image:1.01 .
```

this command will build a docker image with file the mentioned directory , i mention “.” to use the same dir.

## Is Docker needed for SDE roles in IT field today ?

Answer is Yes and No , because Docker is tool used by Devops people but in this modern time its will be useful to learn docker and Kubernetes to standout form the crowd while Appling for a job. Its not at all compulsory for Software Developer Role still today

> Learning daily will make a big difference in a long run .  
> \-rakeshraj .
