Docker Basics
Tags: docker
Published: 2024-01-26 14:24:44

_What Docker is trying to resolve_

1.Application solution works properly in local environment but when moving to different environment like Test/ Prod -  Will see performance degradation 
2.It works fine in  my machine and its not working in test/ prod machines  - May be some configurations may be missed while moving to test/prod machines

**Docker**

- It allows to  have sealed Air-tight containers
- It wraps up the entire code
- It works fine when moving from one environment to other environment
- Docker  packaged with code, dependencies ,config, process, OS Chunks


> Docker is an open-source technology used mostly for 
- Developing
- Shipping
- Running Applications

**Why Docker**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjm7ldkb5s6dxr63949t.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5xmy755n9b6s5euogrdd.png)


> 
- Docker is an OS-level virtualization software platform that enables developers and IT administrators to create, deploy and run applications in a Docker with all their dependencies.
- Docker container is a lightweight software package that includes all the dependencies (framework, libraries, etc.) required to execute an application

**What is Docker**
`Docker is a tool which is used to automate the deployment of applications in lightweight containers so that applications can work efficiently in different environments.`

- Multiple containers run on the same hardware
- Maintains isolated applications
- High productivity
- Quick and easy configuration

**What is Containerisation**
`It is the process of packing the application and all its dependencies to execute them in an efficient and hassle-free way across different environments. A single unit of this bundled  package is known as a Container.`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cak1thclkldz0rohawy1.png)

**How does Docker Work**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmwiuo4aqs7qm7md7b2m.png)

- Docker Engine or Docker is the base engine installed on your host machine to build and run containers using Docker components and services.
- It uses a client-service architecture.
- Docker Client and Server communicate using Rest API.
 
**What happens at this point**

- Docker client is a service which runs a command. The command is translated using REST API and is set to the Docker Daemon (server).
- Then, Docker Daemon checks the client request and interacts with the operating system in order to create or manage containers.


**Components of Docker**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9i7eix9z2zekyl71x6pk.png)

**Docker Architecture**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smi36h6kllajl5diunbd.png)

References : https://docs.docker.com/get-started/overview/

**Docker Client and Server**

- Docker Works in a client-server architecture
- The client sends the control commands to the Docker Daemon through a REST API.
- Docker Daemon is responsible for building, running and distributing the containers.
- The Client and Daemon can be on the same system or the client can connect to a remote Daemon.

- Docker Client is accessed from the terminal and a Docker Host runs the Docker Daemon and registry.
- A user can build Docker Images and run Docker Containers by passing commands from the Docker Client to Docker Server

> Note : The machine running the docker server is called as Docker Host

**Docker Image**

- Docker Image is a template with instructions, which is used for creating Docker Containers
- A Docker Image is build using a file called Docker File
- Docker Image is stored in a Docker Hub or in a repository  (like registry.hub.Docker.com)

> Note : A Docker File is a text file which contains commands for building a Docker Image


**Docker Container**

- Numerous Docker Container run on the same infrastructure and share operating system(OS) with its other containers
- Here each application runs in isolation

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gurhhgkx9ihllux86ws7.png)

**Docker Desktop**
Docker Desktop is an easy-to-install application for your Mac, Windows or Linux environment that enables you to build and share containerized applications and microservices. 
Docker Desktop includes the Docker daemon (dockerd), the Docker client (docker).
for more information [Docker Desktop](https://docs.docker.com/desktop/)

Installing Docker desktop  : [Download](
https://docs.docker.com/desktop/install/windows-install/)

**Docker Registry**

- Docker Registry is an open source server-side service used for hosting and distributing images
- Docker also has its own default registry called **Docker Hub**
- Here,images can be stored in either public or private respositories
- Pull and Push are the commands used by users in order to interact with a Docker Registry
- In order to build a container, pull command is used to get a Docker Image from the Docker repository

`Docker pull <image>:<tag>  :pulls an images from Docker Registry`

- With push command, a user can store the Docker Image in Docker Registry

`Docker push <image>:<tag>  :pushes an image to Docker Registry`


**Virtual Machine Vs Docker**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w07aw41wkvkai22llbtd.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inl780ob7zs8w9ojoj3h.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ujnfjee7emvchyteitt7.png)

**Container Lifecycle**
A new created container can be in one of six states:

-  Created
-  Running
-  Paused
-  Stopped
-  Restarted
-  Dead

**Docker Commands**

- docker run : Creates a container from an image
- docker start : Starts an already stopped container(s)
- docker stop : Stop an active container
- docker build :Builds a docker image from a docker file
- docker pull  : Pulls re-created images from a specific repository
- docker export : Exports container filesystem to a .tar achieve file
- docker images : List the docker images currently on the local system
- docker search : Searches repository for the specified image
- docker ps  : Lists all active containers running on the system
- docker kill : kills an active container without any grace period to shut down its  processes
- docker commit : Creates a new image out of an already active container
- docker login :Command to login to docker hub repository

For further study refer
[9 Tips for Containerizing Your .NET Application
](https://www.docker.com/blog/9-tips-for-containerizing-your-net-application/#:~:text=First%2C%20Docker%20containers%20can%20act,moving%20to%20a%20production%20environment)


Conclusion : Discussed about the basics of docker vs vm, docker architecture and docker commands and will post a new article next Friday with the docker files , docker build commands etc.,

**AWS Services to run containers** : Refer to my previous blog on[APP Runner](https://dev.to/aws-builders/app-runner-2nb7)
💬 If you enjoyed reading this blog post and found it informative, please take a moment to share your thoughts by leaving a review and liking it 😀 and follow me in [linkedin](https://www.linkedin.com/in/srinivasuluparanduru/)