Docker
1. What is Docker?
Docker is a containerization platform that allows you to create, deploy, and run
applications in lightweight, portable containers ensuring they run consistently across
different environments.
2. Docker Components
Container → A running instance of a Docker image, providing an isolated
environment for applications.
Image → A read-only blueprint or template used to create containers.
Dockerfile → A textile or a script containing instructions to build a Docker image
(specifies base image, dependencies, and commands).
Docker Engine → The software that runs and manages containers.
3. Docker Registry
A Docker Registry is used to store and manage images.
Public Registry → Docker Hub (default, open for public access).
Private Registry → Used within organizations for internal sharing.
Docker Architecture
Docker Architecture:
Docker follows a client-server architecture with three main components:
1. Docker Client → Sends commands to the Docker daemon (e.g., docker run, docker
build).
2. Docker Daemon (Server) → Runs on the host machine, manages containers and
images.
a. Containers: Lightweight, isolated units running apps and their dependencies.
b. Images: Read-only blueprints for creating containers.
3. Docker Hub/Registry → Stores Docker images
a. Public Registry → Docker Hub.
b. Private Registry → Used for internal sharing.
How It Works:
The Client communicates with the Daemon using REST API.
The Daemon pulls images from the Registry and creates containers.
Containers run isolated but share the host OS kernel, making them lightweight.
Note: -
1. Docker Engine = Docker Daemon (dockerd) + REST API + CLI .
The entire container runtime system that includes the Docker Daemon, CLI, and
REST API. It is the core of Docker.
2. Docker Daemon (dockerd) is just one part of the Docker Engine responsible for
handling container-related operations.It is a background process that runs on the
host machine and manages containers, images, networks, and volumes. It is a part of
the Docker Engine.
Frequently Used Docker Commands:
1. docker ps: List all running containers.
2. docker ps -a: List all containers, including stopped ones.
3. docker run -d --name container_name image_name:tag: Run a container in
detached mode with a specified name.
4. docker stop container_name: Stop a running container.
5. docker start container_name: Start a stopped container.
6. docker restart container_name: Restart a running container.
7. docker exec -it container_name /bin/bash: Start an interactive shell in a
running container.
8. docker images: List all images on the local system.
9. docker build -t image_name:tag .: Build an image from a Dockerfile in the
current directory.
Virtual Machine vs Container
Sr.
Feature Virtual Machine (VM) Docker Container
No.
A virtualized instance of a full A lightweight instance of an image.
1 Architecture OS (with kernel) running on a Shares the host OS kernel, running in
hypervisor. isolated environments.
Takes minutes to boot up (the Starts in seconds (as it doesn’t boot an
2 Boot Time
full OS). OS).
Large (GBs) as it includes a Smaller (MBs) as it shares the OS
3 Size
full OS. kernel.
Slower due to the overhead of a Faster, near-native performance due to
4 Performance
full OS and hypervisor. minimal overhead.
Stronger isolation (each VM Processes are isolated but share the
5 Isolation
runs its own OS). same OS kernel.
Less portable; requires a Highly portable across different
6 Portability
compatible hypervisor. environments with Docker installed.
More secure due to full OS
7 Security Less secure, relies on host OS security.
separation.
Suitable for running different
Best for microservices, cloud-native
8 Use Case OS environments on the same
applications, and fast deployments.
hardware.
VMware, VirtualBox, KVM,
9 Examples Docker, Kubernetes, Podman.
Hyper-V.
Docker Architecture (10 Marks)
Docker is a popular open-source platform that helps developers package applications and their dependencies into lightweight, portable containers. It follows a client-server architecture, and
consists mainly of three parts: the Docker Client, Docker Daemon (Server), and Docker Registry.
1. Docker Client:
The Docker Client is what the user interacts with. It is responsible for sending commands such as docker run, docker build, etc., to the Docker Daemon. It uses the Docker CLI (Command
Line Interface) to communicate with the daemon through REST APIs.
2. Docker Daemon (dockerd):
The Docker Daemon runs in the background on the host system. It is the core part of the Docker Engine, which manages containers, images, volumes, and networks.
It performs the following:
Pulls images from Docker Hub or other registries
Creates, starts, stops, and removes containers
Handles container lifecycle management
The daemon shares the host OS kernel with containers, making them lightweight.
3. Docker Registry:
This is where Docker images are stored. The most common public registry is Docker Hub, but private registries can also be used in organizations for internal sharing.
Public Registry: Open access (like Docker Hub)
Private Registry: Restricted, used for internal image sharing
How it Works:
The client sends instructions to the daemon.
The daemon pulls the required image from a registry.
Then, it uses that image to create a container.
Containers run in isolation but share the OS kernel, which makes them efficient and fast.
Note on Docker Engine:
The Docker Engine includes three main parts:
Docker Daemon (dockerd)
REST API for communication
Docker CLI (Client)
The Docker Daemon is a part of the Docker Engine, responsible for container operations.
Common Docker Commands to Remember:
docker ps → List running containers
docker ps -a → List all containers (even stopped)
docker run -d --name mycontainer ubuntu → Run a container in background
docker stop mycontainer → Stop container
docker exec -it mycontainer /bin/bash → Run a command inside container
docker build -t myimage:v1 . → Build image from Dockerfile
Conclusion:
Docker simplifies software development by creating consistent environments through containers. Its architecture, based on a client-server model, ensures smooth communication, efficient
container management, and scalable application deployment.