Docker’s basics
There’s a ton of Docker material out there — blogs, videos, GPTs, LLMs, etc. I’m going to share my personal take on Docker, why it exists, and the bare essentials you need to actually get started without drowning in jargon.
The Birth of Docker
Put simply: Docker lets you run multiple “computers” inside your computer.
Virtual machines (VMs) do this too — but they are heavy, slow to start, and come with a lot of extra baggage (full OS per VM). Docker, on the other hand:
- Lightweight — Shares the host system’s kernel instead of carrying an entire OS.
- Isolated environments — No dependency conflicts between projects.
- Portable — Package your app, send it to someone, and it’ll run exactly the same on their machine.
- Easy setup — No “works on my machine” drama.
- Cloud-ready — Combine it with Docker Hub or GitHub to share pre-built environments instantly.
Think of Docker as:
“A way to give each project its own little private playground… without wasting memory or time.”
Docker Jargon
Docker’s world is full of big scary words. Let’s shrink them down.
| Term | What It Is | Fun Analogy |
|---|---|---|
| Image | Read-only template for your app. | The recipe for baking a cake. |
| Container | A running instance of an image. | The cake itself. |
| Volume | Storage space your container can use. | The fridge where you keep cake leftovers. |
| Dockerfile | Instructions to build your own image. | The handwritten recipe card. |
| Network | Lets containers talk to each other. | A walkie-talkie for cakes (ok, this analogy broke). |
| Docker Compose | A YAML file to run multiple containers together. | The wedding planner coordinating all cakes and guests. |
Docker Hub
Software providers like PostgreSQL, MySQL, Python, and Ubuntu have already containerized their applications and put them on Docker Hub.
You just pull them down, like:
docker pull postgres:15
docker pull python:3.9It’s like saying:
“Hey, I’d like the ready-made cake recipe, version 3.9, please.”
Docker Commands You’ll Actually Use
| Command | What It Does |
|---|---|
docker pull <image> |
Download an image from Docker Hub. |
docker build -t <name> . |
Build an image from a Dockerfile. |
docker run <image> |
Run a container from an image. |
docker run -d <image> |
Run a container in detached (background) mode. |
docker run -p 8000:8000 <image> |
Map host port to container port. |
docker ps |
List running containers. |
docker ps -a |
List all containers (including stopped ones). |
docker stop <id> |
Stop a running container. |
docker start <id> |
Start a stopped container. |
docker restart <id> |
Restart a container. |
docker exec -it <id> bash |
Open a shell inside a running container. |
docker logs <id> |
View logs of a container. |
docker rm <id> |
Remove a stopped container. |
docker rm -f <id> |
Force remove a running container. |
docker rmi <image> |
Remove an image. |
docker images |
List all images on your system. |
docker volume ls |
List all Docker volumes. |
docker network ls |
List Docker networks. |
docker inspect <id> |
Show detailed info about a container or image. |
docker compose up |
Start services defined in docker-compose.yml. |
docker compose up --build |
Rebuild images before starting. |
docker compose down |
Stop and remove services from docker-compose.yml. |
Cleanup Commands (Your Sanity Savers)
Sometimes you just want a clean slate:
docker container prune # Remove all stopped containers
docker image prune # Remove unused images
docker volume prune # Remove unused volumes
docker network prune # Remove unused networks
docker system prune # Remove all unused containers, images, volumes, networks
docker system prune -a # Remove everything, including unused imagesCaution: docker system prune -a is like pressing the “nuke” button — it will delete all images and containers not currently running.
If you like, I can merge this full command cheat sheet into your Docker blog post so it becomes a one-stop beginner + reference guide. That way, you don’t have to maintain two separate docs.
A Simple FastAPI Dockerfile
Here’s a minimal example for a FastAPI app:
FROM python:3.9
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app
CMD ["fastapi", "run", "app/main.py", "--port", "80"]Breaking It Down:
- FROM — The base image (Python 3.9). Think: “Start with a ready kitchen.”
- WORKDIR — Where commands will run inside the container.
- COPY — Move files from your computer into the image.
- RUN — Execute commands when building the image (install dependencies).
- CMD — The default command to run when the container starts.
CMD vs ENTRYPOINT — What’s the Difference?
- ENTRYPOINT → The fixed part of the command that will always run.
- CMD → The part you can override when running the container.
Think of ENTRYPOINT as the cake base (always needed), and CMD as the flavor (you can swap chocolate for vanilla).
Final Thoughts
Docker isn’t magic — it’s just a smart way to package and run software so it’s consistent everywhere. Once you get the basic terms down and try a few builds yourself, you’ll wonder how you ever shipped apps without it. If you still dig deep You know docker compose which is much effient way to orchestrate multiple docker in a streamlined way.