If you’ve ever faced the dreaded “It works on my machine but not on yours” problem — Docker is the hero you need.
Docker allows developers to package applications into isolated environments called containers, ensuring they run the same everywhere.
â
Think of it like this:
You built a school project website that runs fine on your laptop.
But when you copy it to your friend’s system, it crashes because they have a different PHP version.
With Docker, you can package:
into a single container.
Now it works everywhere ð.
Docker has two main parts:
The tool we use to interact with Docker.
Runs commands like:
docker run → Start a containerdocker pull → Download an imageCan also communicate with a remote Docker Daemon over a network.
The engine of Docker running in the background.
Responsible for:
Client ↔ Daemon communicate via:
ð Analogy:
You (client) say “Make tea!” â and the kitchen (daemon) makes it.
If one layer changes, only that part rebuilds.
ð Example:
ubuntudocker pull ubuntu
docker pull ubuntuBy default, containers are ephemeral (data is lost when removed) unless a volume is attached.
ð Flow:
docker container create --name shan ubuntu /bin/bash
docker container create --name shan ubuntu /bin/bashThe core runtime that builds and runs containers locally.
A cloud-based repository to store and share Docker images.
A script with step-by-step instructions to build an image.
Executed top to bottom by the Docker Daemon.
ð Workflow:
Dockerfile → docker build → Docker Image → docker run → Container
â Example:
FROM ubuntu RUN apt-get update && apt-get install -y nginx CMD ["nginx", "-g", "daemon off;"]
FROM ubuntu
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]A service that stores Docker images.
Docker Hub is the most popular public registry.
docker image ls → List imagesdocker pull <image> → Download imagedocker rmi <image> → Remove imagedocker history <image> → View layersdocker run <image> → Run containerdocker ps -a → List containersdocker exec -it <id> /bin/bash → Open terminal inside containerdocker logs <id> → View logsð Example: Run Nginx on port 80
docker run -d -p 80:80 nginx
docker run -d -p 80:80 nginx| Feature | Docker (Container) | Virtual Machine (VM) |
|---|---|---|
| Startup Time | Seconds ⥠| Minutes ð |
| Resource Usage | Lightweight ðŠķ | Heavy ðŧ |
| OS Requirement | Shares Host OS | Needs Full OS |
| Performance | Faster ð | Slower ðĒ |
| Isolation | Process-level | Hardware-level |
ð Example: