DevOps · Beginner Tutorial
Docker Tutorial for Beginners 2026
Quick summary — Docker tutorial for beginners
Docker packages your app and its dependencies into a container that runs anywhere. This guide walks you through Docker from installation to deployment — with real commands, Dockerfile examples, and Docker Compose setups you can try today.
In this guide you will learn:
- Installation — setup Docker on your machine.
- Containers — run, inspect, and manage containers.
- Images & Dockerfiles — build your own images.
- Docker Compose — multi-service apps with one command.
- Deployment — real-world patterns and best practices.
SECTION 01Installation & first container
Let's get Docker running on your machine and spin up your first container. Here's the step-by-step:
| Step | Command | What It Does |
|---|---|---|
| Install | Docker Desktop | Installs Docker engine + CLI |
| Verify | docker --version | Confirms Docker is installed |
| Check engine | docker info | Shows running engine details |
| First container | docker run hello-world | Pulls and runs a sample image |
Install Docker:
1. Go to https://docs.docker.com/get-docker/
2. Download Docker Desktop for your OS
3. Run installer and follow the wizard
4. Start Docker Desktop
5. Open terminal and verify:
$ docker --version
Docker version 26.x.x, build ...
$ docker info
Server:
Containers: 0
Images: 0
...
You're ready to go.
Run your first container:
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
...
Hello from Docker!
This message shows that your installation appears to be working correctly.
# Pull and run an nginx web server
$ docker run -d -p 8080:80 nginx
# Open http://localhost:8080 in your browser — nginx page loads.
# List running containers
$ docker ps
SECTION 02Working with containers
Now that Docker is running, let's learn the essential container commands you'll use daily:
| Command | What It Does | Common Flags |
|---|---|---|
| docker run | Create and start a container | -d (detach), -p (port), -it (interactive) |
| docker ps | List running containers | -a shows all containers |
| docker logs | View container output | -f to follow logs |
| docker exec | Run a command inside a container | -it for an interactive shell |
| docker stop | Stop a running container | docker rm removes it |
# Run nginx detached on port 8080
docker run -d -p 8080:80 --name webserver nginx
# List running containers
docker ps
# Show all containers (running + stopped)
docker ps -a
# View logs
docker logs webserver
docker logs -f webserver
# Open an interactive shell
docker exec -it webserver bash
# Stop and remove
docker stop webserver
docker rm webserver
# Interactive shell into a container
$ docker run -it ubuntu bash
root@container:/# ls
root@container:/# apt-get update
root@container:/# exit
# Run a command and exit
$ docker run --rm ubuntu echo "hello from ubuntu"
# Useful: cleanup
docker stop $(docker ps -q)
docker rm $(docker ps -aq)
docker system prune -a
SECTION 03Images & Dockerfile
To package your own application, you need to build a Docker image from a Dockerfile. Here's how it works:
| Instruction | Purpose | Example |
|---|---|---|
| FROM | Base image | FROM python:3.12-slim |
| WORKDIR | Set working directory | WORKDIR /app |
| COPY | Copy files into image | COPY . . |
| RUN | Run command during build | RUN pip install -r requirements.txt |
| CMD | Default command when container starts | CMD ["python", "app.py"] |
# Dockerfile — Python Flask app
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]
# Build the image
$ docker build -t my-flask-app:v1 .
# Check images
$ docker images
# Run the container
$ docker run -d -p 5000:5000 --name myapp my-flask-app:v1
# Push to Docker Hub (optional)
$ docker login
$ docker tag my-flask-app:v1 yourname/my-flask-app:v1
$ docker push yourname/my-flask-app:v1
pip install) before frequently
changing ones (like COPY . .) to make rebuilds faster.
SECTION 04Docker Compose
Real apps need more than one service — a web app, a database, maybe Redis. Docker Compose lets you define them all in a single YAML file and start everything with one command.
# docker-compose.yml — Flask + Postgres + Redis
version: "3.9"
services:
web:
build: .
ports:
- "5000:5000"
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/app
depends_on:
- db
- redis
db:
image: postgres:16
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: app
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
volumes:
postgres_data:
# Start all services
docker compose up -d
# View logs from all services
docker compose logs -f
# View logs from one service
docker compose logs -f web
# Rebuild after Dockerfile changes
docker compose up -d --build
# Stop and remove containers + networks
docker compose down
# Stop and remove containers + volumes (deletes data!)
docker compose down -v
# Run a command in a service
docker compose exec web bash
SECTION 05Deployment & best practices
Here's how to take your Docker knowledge from laptop to production:
Where to deploy Docker containers:
Simple / beginner-friendly:
□ Render, Railway, Fly.io (git-push deploy)
□ DigitalOcean App Platform
□ Docker Hub + a single VM (docker run)
Intermediate:
□ AWS ECS / Fargate
□ Google Cloud Run
□ Azure Container Apps
Advanced:
□ Kubernetes (EKS, GKE, AKS)
□ Self-managed clusters
□ Helm charts
Start simple. Move to Kubernetes when
your app actually needs it.
Docker best practices:
Images:
□ Use slim/alpine base images
□ Multi-stage builds for smaller images
□ Pin versions (python:3.12-slim, not latest)
□ Don't run as root — use USER
Dockerfile:
□ Order layers by change frequency
□ Combine RUN commands with &&
□ Use .dockerignore (exclude node_modules, .git)
Runtime:
□ Mount volumes for data
□ Set resource limits (--memory, --cpus)
□ Use env vars for config, never hardcode secrets
□ Log to stdout/stderr
Security:
□ Scan images (docker scout, trivy)
□ Keep images updated
□ Don't leak secrets into image layers
Daily practice tracker:
Date: _________
☐ Pull and run a new image (15 min)
☐ Read Dockerfile of a public image (15 min)
☐ Practice 3 commands (10 min)
☐ Write notes / screenshot
Today's learnings:
1.
2.
3.
Tomorrow's target:
1.
2.
SECTION 06Interview Q&A — Docker
Q1What is the difference between a Docker image and a container?
An image is a read-only template (the recipe). A container is a running instance of an image (the cake). You can run multiple containers from the same image.
Q2How is Docker different from a virtual machine?
VMs virtualise the hardware and run a full OS. Containers share the host OS kernel, making them much lighter and faster to start — seconds vs minutes.
Q3What is a Dockerfile?
A text file with instructions (FROM, RUN, COPY, CMD) that Docker uses to build an image. Think of it as a recipe for your environment.
Q4How do you persist data in Docker?
Use volumes (managed by Docker) or bind mounts (host directory). Volumes survive container deletion and are the recommended way to persist data.
Q5What is Docker Compose used for?
Docker Compose defines and runs multi-container apps using a
single YAML file. You can start a web app, database, and cache
together with docker compose up.
SECTION 07Test yourself — Docker quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
Do I need to know Linux before Docker?
Basic Linux helps — file system, permissions, shell commands. You don't need to be an expert, but familiarity with the terminal makes Docker much easier.
Is Docker free?
Docker Desktop is free for personal use, education, and small businesses. Larger companies need a paid subscription. The Docker engine itself is open source.
How long does it take to learn Docker?
Basics: 1–2 weeks. Comfortable with Compose: 3–4 weeks. Production-ready with security and deployment: 2–3 months.
Do I need Docker if I use Kubernetes?
Yes — Kubernetes runs containers, which you build with Docker (or similar tools). Learning Docker first is strongly recommended.
Is Docker still relevant in 2026?
Absolutely. Docker remains the standard for building and packaging containers. Alternatives like Podman exist, but Docker skills are still in high demand.
SECTION 09Related reads
Classroom & online · Noida
Start your DevOps journey
Our Data Analytics Training Course is designed to help you recover and rebuild — with skills, projects, and interview prep that get you hired.
₹15,500 · full programme- Docker + Compose fundamentals
- Hands-on labs
- Deployment projects
- Weekday & weekend batches