Docker

Docker is an Open platform for developing, shipping, and running applications.

Docker allows you to separate application from infrastructure so that you can deliver your application quickly.

Means: Docker lets you to package (code, dependencies and configurations ) into a container which runs same regardless of where it is deployed(Laptop, server, cloud etc..)

This decouples apps from underlaying infrastructure(like operating system, system libraries etc..)

so you don't have to worry about infrastructure that breaking your app. so we can develop, test, deploy apps quickly.

with Docker you can manage your infrastructure in the same ways you manage application.

Even though your app is separated from infrastructure (it doesn’t depend on host system), you still define and control the infrastructure using code files that Docker understands.



📁 Example: Dockerfile and docker-compose.yml

Imagine your app needs:

  • Python 3.10

  • MongoDB

  • Redis

  • Some environment variables

  • A custom network

You can define all of this as code:
Dockerfile (infrastructure for your app container)

FROM python:3.10
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "main.py"]

docker-compose.yml (infrastructure for running all services together)

version: "3"
services:
  app:
    build: .
    ports:
      - "5000:5000"
    environment:
      - ENV=production
  mongo:
    image: mongo
  redis:
    image: redis


 So how is it version-controlled?

You store these files (Dockerfile, docker-compose.yml) in Git, just like your app code. That means:

  • Any changes to your infrastructure setup are tracked.

  • You can rollback if something breaks.

  • Teams can collaborate, review, and test infra changes like code.

So now:

Infrastructure = Code files = Tracked, repeatable, portable

This is what Infrastructure as Code (IaC) means in the Docker context.

Docker lets you package your application (along with everything it needs — like code, libraries, and settings) into a small box called a container.

  • Each container is separate from others and from the computer it runs on.

  • You can run many containers at the same time on one machine.

  • It doesn’t matter what's installed on the machine — the container has everything it needs.

  • You can share your container with others, and it will work exactly the same for them.

When To Use?

1. Fast, consistent delivery of your applications

Simple Explanation:

Docker makes it easy to package your app and everything it needs into one unit (a container).
So, it runs the same way everywhere — on your laptop, a test server, or in production.
This means you can build once and run anywhere, without worrying about "it works on my machine" issues.

Example:
You build your app on your laptop → Send it to the team or deploy to a server → It works exactly the same.


2. Responsive deployment and scaling

Simple Explanation:

With Docker, you can start or stop apps quickly, and run more copies of your app when needed.
This helps you handle more users or traffic easily.

Example:
Your website is getting more visitors → You launch 5 containers instead of 1 → Everything stays smooth.


3. Running more workloads on the same hardware

Simple Explanation:

Docker containers are lightweight, meaning they use less memory and CPU than traditional virtual machines.
So, you can run more applications on the same machine without slowing it down.

Example:
Instead of running 2 big apps on a server, Docker lets you run 5 or 10 smaller containers — saving money and resources.


🔧 Docker Architecture - Simple Steps


1. Docker works in a Client-Server model

  • Think of it like this:
    The Docker client is you (giving commands), and the Docker daemon is the worker (doing the job).


2. You talk to Docker using commands

  • You type commands like docker run, docker build, etc.

  • These go to the Docker client.


3. The Docker client sends the commands to the Docker daemon

  • The client talks to the Docker daemon using something called a REST API.

  • Communication happens through UNIX sockets (if on the same system) or network (if remote).

  • Note: Think of a UNIX socket like a direct pipe inside a house (your computer), where two people (programs) pass messages back and forth — no need to go outside (network).

  • In the context of Docker:

    • The Docker client sends commands (like docker run) to the Docker daemon.

    • If both are on the same machine, they usually communicate through a UNIX socket file — usually found at:

    /var/run/docker.sock

    This file acts like a tunnel between the client and the daemon.


4. The Docker daemon does all the heavy work

  • It:

    • Builds containers

    • Runs containers

    • Manages images and networks

  • It's like the engine running in the background.


5. Docker client and daemon can be on:

  • The same computer (local)

  • Different computers (remote)

Example: Your laptop runs the client → Connects to a daemon running on a server.


6. Docker Compose is a special Docker client

  • It's used when you want to manage multiple containers as one application.

  • For example, a web app + database + Redis → all started with one docker-compose up.


✅ Summary in one line:

You (client) give Docker commands → Docker daemon does the work → Everything runs in containers.


🧱 1. Docker Architecture — The Big Picture

Docker works like a team where different parts have different jobs.


🔧 The Docker Daemon (dockerd)

  • This is the main worker behind the scenes.

  • It listens for instructions (like build, run, stop).

  • It manages:

    • Images

    • Containers

    • Networks

    • Volumes

  • It can also talk to other Docker daemons on other machines.

Think of it as: the person who does the heavy lifting.


👨‍💻 The Docker Client (docker command)

  • This is the tool you use to give instructions.

  • You type commands like:

    docker run ubuntu docker build .
  • The client sends your command to the daemon, which executes it.

Think of it as: you giving orders to the worker (daemon).


🖥️ Docker Desktop

  • A ready-to-use app for Mac, Windows, or Linux.

  • It gives you:

    • Docker daemon

    • Docker client

    • Docker Compose

    • Kubernetes support

    • GUI (Graphical Interface)

  • Makes using Docker easy without command-line setup.

Think of it as: an all-in-one toolbox.


📦 Docker Registries

  • A place where Docker images are stored and shared.

  • Docker Hub is the most common public registry.

  • You can also create your own private registry.

  • Commands:

    • docker pull → download image

    • docker push → upload your image

Think of it as: an app store for containers.


🧱 2. Docker Objects — What Docker Works With


🖼️ Images

  • A template for creating containers.

  • It includes your app, libraries, and system tools.

  • You can build your own image using a Dockerfile.

  • Each instruction in the Dockerfile creates a layer, so changes are fast and efficient.

Example:

  • Start with Ubuntu image

  • Add Python and your app

  • Result: Custom image

Think of it as: a recipe for your app.


📦 Containers

  • A running version of an image.

  • It can be started, stopped, moved, or deleted.

  • You can attach storage, connect to a network, and run code inside.

  • It’s isolated from other containers and the host machine.

Think of it as: a live app made from the image (like baking from a recipe).


🔁 Example command:

docker run -it ubuntu /bin/bash

What this does:

  1. Downloads Ubuntu image if not already present.

  2. Creates a new container.

  3. Adds a writable layer (so you can make changes).

  4. Connects it to the default network.

  5. Starts the container and opens bash shell.

  6. You can now interact with it in your terminal.


⚙️ 3. Under the Hood — How Docker Works Internally

  • Docker is written in Go (a programming language).

  • It uses Linux features like namespaces to keep containers isolated.

Namespaces:
They give each container its own space (like private folders, network, processes).

This is how multiple containers can run on the same machine without affecting each other.


🧠 Summary in Simple Words

PartWhat it Does
Docker Daemon (dockerd)Worker that does the real job
Docker Client (docker)Tool you use to give commands
Docker DesktopEasy all-in-one app to use Docker
RegistryOnline storage for container images
ImageTemplate for your app
ContainerRunning version of an image
NamespacesKeeps containers isolated

 click here for Docker Desktop Installation steps.

✅ Step-by-Step: Run Your First Docker Container

🧱 Prerequisite:


🚀 Step 1: Open Terminal

  • Open Command Prompt, Terminal, or PowerShell depending on your OS.


▶️ Step 2: Run the Container

Copy and paste this command into the terminal and hit Enter:


docker run -d -p 8080:80 docker/welcome-to-docker

🔹 What this does:

  • docker run: starts a container

  • -d: runs it in the background (detached mode)

  • -p 8080:80: maps your computer's port 8080 to the container's port 80

  • docker/welcome-to-docker: this is the demo Docker image to run


🌐 Step 3: Open the Website

You should see a welcome page from Docker 🎉


Comments