Skip to main content

Command Palette

Search for a command to run...

Docker

Updated
โ€ข7 min readโ€ขView as Markdown
Docker
A

DevOps Engineer | Sharing insights on Kubernetes, Docker, CI/CD & Cloud | Writing to simplify complex tech

Docker we call as containerization

๐Ÿ”น What is Docker?

Docker is an open-source platform that helps you build, package, and run applications in containers.
A container is a lightweight, portable unit that bundles:

  • Application code

  • Runtime

  • Libraries

  • Dependencies

This ensures your app runs the same everywhere (developer laptop, test, production, cloud).


๐Ÿ”น Why Docker?

Without Docker, apps often face the classic problem:

"It works on my machine but not in production."

Docker solves this by putting everything the app needs into a container that can run anywhere.


๐Ÿ”น Key Concepts

  1. Image โ†’ A snapshot/blueprint of your app (e.g., Python + Flask app).

  2. Container โ†’ A running instance of an image.

  3. Dockerfile โ†’ A script to build an image (instructions on how to package the app).

  4. Docker Hub โ†’ Public registry to share and download Docker images.


๐Ÿ”น Advantages

โœ… Portability โ†’ Runs the same on Windows, Linux, Mac, or cloud.
โœ… Lightweight โ†’ Uses fewer resources than Virtual Machines (VMs).
โœ… Faster deployment โ†’ Containers start in seconds.
โœ… Isolation โ†’ Each container has its own environment (no conflicts).
โœ… Scalability โ†’ Works well with Kubernetes and microservices.


๐Ÿ”น Docker vs Virtual Machine

  • VM โ†’ Heavy, full OS per instance.

  • Docker Container โ†’ Lightweight, shares host OS kernel.

To develop application we have two types of process:

Monolithic :

A monolithic architecture (or simply monolithic) is a traditional software design style where the entire application is built as a single, unified unit.

Hereโ€™s a breakdown:

๐Ÿ”น What it means

  • All features (UI, business logic, database access, etc.) are tightly coupled and packaged together in one codebase.

  • Typically deployed as a single executable or a single service.

๐Ÿ”น Characteristics

  1. Single codebase โ†’ All modules (authentication, payments, product catalog, etc.) are bundled together.

  2. Single deployment โ†’ Even if you change a small feature, you must redeploy the whole application.

  3. Tightly coupled โ†’ Components are highly dependent on each other.

  4. Shared database โ†’ Usually one database is used for the entire app.

๐Ÿ”น Advantages

  • Easy to develop initially (simple structure).

  • Straightforward testing (everything in one place).

  • Easier debugging (logs are centralized).

  • Good performance for small-scale apps (no network calls between services).

๐Ÿ”น Disadvantages

  • Scalability issues โ†’ Can only scale the whole app, not specific parts.

  • Slower development over time (large codebase becomes hard to manage).

  • Limited flexibility โ†’ Canโ€™t easily adopt new tech for just one part of the system.

  • Risky deployment โ†’ A bug in one part may bring down the entire system.

Microservices:

๐Ÿ”น What is Microservices Architecture?

A microservices architecture is a way of designing software applications as a collection of small, independent services.
Each service focuses on doing one specific function well and communicates with other services using lightweight protocols (like REST APIs, gRPC, or messaging queues).


๐Ÿ”น Characteristics

  1. Independently deployable โ†’ Each service can be built, tested, and deployed without affecting others.

  2. Loosely coupled โ†’ Services communicate but donโ€™t depend tightly on each other.

  3. Polyglot flexibility โ†’ Different services can use different programming languages, databases, or frameworks.

  4. Decentralized data โ†’ Each microservice often has its own database (no single shared DB).


๐Ÿ”น Advantages

โœ… Scalability โ†’ You can scale only the services that need more resources (e.g., scaling "payment" service, not the whole app).
โœ… Faster development โ†’ Small, focused teams can work on different services in parallel.
โœ… Resilience โ†’ Failure in one service doesnโ€™t bring down the entire system.
โœ… Technology flexibility โ†’ Different services can adopt different technologies.


๐Ÿ”น Disadvantages

โš ๏ธ Complexity โ†’ Managing many services, deployments, and inter-service communication is harder.
โš ๏ธ Operational overhead โ†’ Needs strong DevOps practices (CI/CD, containerization, monitoring, logging).
โš ๏ธ Network dependency โ†’ More API calls across services โ†’ latency and failure handling needed.

How Docker Works Containerization/Architecture:

Before Docker we have to install all dependencies in all environments invidually

After Docker for application run we can create image along with his dependencies

eg: war+Java+Tomcat+Mysql = Image (That process called as Containerization)

๐Ÿ”น What is Containerization?

Containerization is the process of packaging an application and all its dependencies (libraries, configs, runtime, etc.) into a container so that it can run consistently across different environments.

It ensures that your application works the same on developer laptop, test server, or cloud.

๐Ÿ”น Benefits of Containerization

โœ… Portability โ†’ โ€œBuild once, run anywhere.โ€
โœ… Consistency โ†’ Eliminates โ€œworks on my machineโ€ problem.
โœ… Lightweight โ†’ Uses fewer resources than VMs (no full OS inside each container).
โœ… Scalability โ†’ Easy to scale containers up/down in microservices or cloud environments.
โœ… Faster deployment โ†’ Containers start in seconds vs minutes for VMs.

How Docker Works?

First we need to pull the base image from registry and make some modification using Dockefile. Once we build the Dockerfile, it will create docker image and we can run the image to create a container.

NOTE: To create a container, we need image.

Docker Architecture:

Docker architecture majorly contains this 3 components

  1. Client

  2. Host

  3. Registry

  4. Docker Client: The Docker client is used by users which interact with Docker, when we use such commands to create a container, start the container or delete the container, the client sends these commands to Docker Daemon to perform that particular action.

  5. Docker Host: It is a system where we installed a docker. Ex: EC2 instance, Azure VM, Personal Lappy etc..

  6. Docker Registry: It is used to store and share the docker images. In registry we can store our images on public or private.it completely stored in cloud.

  7. ๐Ÿ”น What is Docker Daemon?

    The Docker Daemon (dockerd) is a background process that runs on the host machine and manages all Docker-related activities.

  8. It is responsible for:

    • Building images

    • Running containers

    • Managing networks & volumes

    • Communicating with registries (Docker Hub, private registries)


๐Ÿ”น How it Works

  • The Docker Client (docker CLI) does not do the heavy lifting itself.

  • Instead, the client sends commands (via REST API, socket, or HTTP) to the Docker Daemon.

  • The daemon executes those commands and returns the result.


๐Ÿ”น Key Responsibilities of Docker Daemon

  1. Container lifecycle management

    • Create, start, stop, pause, delete containers.

    • Example: docker run โ†’ Daemon creates and starts a container.

  2. Image management

    • Build images from Dockerfiles.

    • Pull/push images to/from registries.

  3. Networking

    • Create and manage networks between containers.
  4. Storage

    • Handle volumes for persistent storage.
  5. API Server

    • Exposes the Docker Remote API so external tools (Kubernetes, CI/CD pipelines) can interact with Docker.

Docker install process:

Take an EC2 instance and launch install Docker in server (yum install docker -y)

Client : Where we execute commands

Is the docker daemon running? then start the docker systemctl start docker

docker images : to see images

docker ps : to see containers

if we have image and then if we run the image then container will create inside container application will run.

Lets pull some images from dockerhub

docker pull nginx โ€”> to pull image (ngnix some application or web server)

For e.g:

How images created and container:

DevOps engineer written a Jenkins docker file then build it will create image and will be push to docker hub then i pull the image from docker hub if i run the image Jenkins container will create .

Lets create container using Nginx image

docker run -itd --name devops -p 1111:80 nginx โ€”โ†’ ( to create container)

itd : interactive terminal **detached (**foreground and background process to always run in background)

-p : used for publishing the port number to access the application

Ports are used to access the application we can give anything randomly

1111:Host port( we can take anything)

container port: 80: Based on image (web server ngnix port number is 80)

run the below command to create container

docker ps : to see containers

container was created as shown above

To access the application : Public ip of server and port number as shown below.