1. What is Docker?
Docker is a platform that packages an
application and everything it needs to run into a portable unit called a
container.
In simple words:
Docker = Package your
application + dependencies + configuration so it can run consistently anywhere.
For example, suppose you build a Python application.
Without Docker, your application might require:
- Python
3.12
- Flask
- Specific
Python libraries
- Linux
packages
- Environment
variables
- Particular
configuration
Your application may work perfectly on your computer
but fail on another server because the environment is different.
With Docker, you package the application and its
required environment into a Docker image, and then run that image
as a container.
Simple example
Your Python Application
↓
Dockerfile
↓
Docker Image
↓
Docker
Container
↓
Runs
consistently
2. Docker vs Virtual Machine
This is one of the most important concepts.
Virtual Machine
Physical Server
↓
Hypervisor
↓
VM 1 VM 2
OS OS
App App
Each VM normally has its own complete operating
system.
Docker
Physical Server
↓
Docker Engine
↓
Container 1
Container 2
App App
Containers share the host's operating-system kernel,
making them generally
lighter and faster to start
than full VMs.
Easy comparison: Docker VS Virtual Machine
Important:
Docker containers are not simply "small VMs."
They use
operating-system-level isolation.
3. Important Docker Terms
You should understand these before moving into
advanced Docker.
a. Docker Engine
The software that runs and manages Docker containers.
Docker CLI
↓
Docker Engine
↓
Containers
b. Docker Image
A read-only template containing everything
required to create a container.
Examples:
python:3.12
nginx:latest
ubuntu:24.04
mysql:8
Think:
Image = Blueprint
c. Docker Container
A running instance of an image.
Think:
Container = Running application created
from the blueprint
For example:
nginx image
↓
Container 1
Container 2
Container 3
One image can be used to create multiple containers.
d. Dockerfile
A text file containing instructions for creating a
Docker image.
Example:-
FROM python:3.12
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY .
CMD ["python", "app.py"]
e. Docker Registry
A place where Docker images are stored.
The most popular public registry is Docker Hub.
For example:
Dockerfile
↓
Docker Image
↓
Docker Hub
↓
Pull image on another server
↓
Run container
4. Docker's Basic Workflow
You should memorize this workflow:
Write Application
↓
Create Dockerfile
↓
Build Image
↓
Test Image
↓
Push Image to Registry
↓
Pull Image on Server
↓
Run Container
For example:
Python App
↓
Dockerfile
↓
my-python-app:v1
↓
Docker Hub
↓
AWS EC2
↓
Docker Container
This is where Docker becomes extremely useful in Cloud
+ DevOps.
5. Docker Commands
Once Docker is installed, start with these commands.
First Docker Commands — Quick Reference
Table
|
N |
Docker Command |
What It Does |
|
|
1 |
docker --version |
Checks the installed Docker version. |
|
|
2 |
docker info |
Displays detailed information about the Docker
installation and Docker Engine. |
|
|
3 |
docker pull nginx |
Downloads the Nginx Docker image from
Docker Hub. |
|
|
4 |
docker images |
Lists all Docker images available on your system. |
|
|
5 |
docker run nginx |
Creates & starts a new container using the Nginx
image. |
|
|
6 |
docker run -d nginx |
Runs an Nginx container in the background
(detached mode). |
|
|
7 |
docker ps |
Shows currently running containers. |
|
|
8 |
docker ps -a |
Shows all containers, including stopped
containers. |
|
|
9 |
docker stop <container_id>, ex-docker stop
abc123 |
Stops a running container. |
|
|
10 |
docker rm <container_id>, ex- docker rm
abc123 |
Removes a stopped container. |
|
|
11 |
docker rmi <image_id>, ex-docker rmi abc123 |
Removes a Docker image from your system. |
6. Docker Port Mapping
Suppose an application inside a container listens on:
Port 80
You can expose it through your host machine:
docker run -d -p 8080:80 nginx
Meaning:
Host Machine Container
----------- ---------
8080 ───────────────→ 80
You access:
http://localhost:8080
The request goes:
Browser
↓
localhost:8080
↓
Docker
↓
Container:80
↓
Nginx
The networking knowledge will make Docker networking
much easier to understand.
7. Docker Volumes
Containers are generally treated as disposable. If
important data exists only inside a container,
you can lose it when the container is removed.
Volumes provide
persistent storage.
Docker Container
↓
Volume
↓
Persistent Data
Example:
docker volume create mydata
Then:
docker run -d \
-v
mydata:/data \
nginx
Bind mount = Host folder/file connected to
container
Ex-
Host C:\project → Container /app
Persistent storage = Storage that keeps
data even after a container is stopped or deleted.
Docker volumes are commonly used for this.
Ex-
Database data remains after container recreation.
Container filesystem = Container's own
temporary storage
Ex-
/app, /tmp, /var/log inside the container
8. Docker Networking
Important Docker networking concepts:
- Bridge
network
- Host
network
- None
network
- Custom
networks
- Container-to-container
communication
- Port
mapping
- DNS
between containers
- Network
isolation
Docker Network
│
┌──────────┴──────────┐
↓ ↓
Frontend Backend
Container Container
│
↓
Database
Container
Instead of connecting applications using random IP
addresses, Docker's custom networks
allow containers to communicate using
container/service names.



