Docker changed how we build, ship, and run software. This tutorial covers everything a beginner needs to go from zero to running containerized applications.
What is Docker?
Docker packages your application and all its dependencies into a container — a lightweight, portable unit that runs the same everywhere: your laptop, staging server, or production cloud.
Before Docker: "It works on my machine" was the most common excuse in software development. Different OS versions, library conflicts, and environment mismatches caused endless deployment problems.
After Docker: Build once, run anywhere. The container includes everything the app needs.
Install Docker
Ubuntu/Debian:
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# Log out and back in
docker --versionmacOS:
brew install --cask docker
# Open Docker Desktop
docker --versionYour First Container
docker run hello-worldThat command:
1. Pulled the hello-world image from Docker Hub
2. Created a container from that image
3. Ran the container
4. Printed a message and exited
Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Working with Images
Search for images:
docker search nginxPull an image:
docker pull nginx:latestList your images:
docker imagesRunning Containers
Run Nginx web server:
docker run -d -p 8080:80 --name webserver nginxBreaking it down:
- -d — Run in background (detached)
- -p 8080:80 — Map host port 8080 to container port 80
- --name webserver — Give the container a name
Visit http://localhost:8080 — you have a web server running.
Useful commands:
docker ps # List running containers
docker ps -a # List all containers (including stopped)
docker logs webserver # View container logs
docker exec -it webserver bash # Shell into container
docker stop webserver # Stop container
docker rm webserver # Remove containerBuilding Custom Images
Create a Dockerfile for a Node.js app:
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]Build and run:
docker build -t my-app .
docker run -d -p 3000:3000 my-appMulti-Stage Builds
Keep images small by separating build and runtime:
# Build stage
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/server.js"]Volumes — Persistent Data
Containers are ephemeral — data is lost when they stop. Volumes persist data:
# Named volume
docker volume create mydata
docker run -d -v mydata:/data my-app
# Bind mount (map host directory)
docker run -d -v $(pwd)/data:/app/data my-appGet weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Networking
Containers communicate through Docker networks:
# Create a network
docker network create mynet
# Run containers on the same network
docker run -d --network mynet --name db postgres:16
docker run -d --network mynet --name app -e DB_HOST=db my-appThe app container can reach db by hostname — Docker handles DNS.
Docker Compose
Define multi-container applications in one file. Create docker-compose.yml:
services:
web:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/mydb
depends_on:
- db
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=mydb
volumes:
pgdata:Run the entire stack:
docker compose up -d # Start everything
docker compose logs -f # Follow logs
docker compose down # Stop and clean upEssential Docker Commands
| Command | Purpose |
|---|---|
docker build -t name . | Build image from Dockerfile |
docker run -d -p H:C name | Run container (host:container ports) |
docker ps | List running containers |
docker logs name | View container logs |
docker exec -it name sh | Shell into container |
docker compose up -d | Start multi-container app |
docker system prune | Clean unused resources |
What's Next?
Our Docker Fundamentals course goes hands-on with real lab environments — build, debug, and deploy containers without any local setup. The first lesson is free.
---
Ready to go deeper? Check out our hands-on course: Docker Fundamentals — practical exercises you can follow along on your own machine.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Docker Volumes and Persistent Data
Manage persistent data in Docker with named volumes and bind mounts. Backup strategies, restore procedures, and container data sharing.
Docker Compose Tutorial for Devs
Master Docker Compose for local development. Multi-service stacks with databases, caching, and hot reload in one command.
Podman vs Docker Comparison 2026
Podman vs Docker in 2026: rootless containers, daemonless architecture, native pod support, and when to choose each runtime.
Domain-Specific AI Models Guide
Build and deploy domain-specific AI models with fine-tuning, RAG, and specialized training data for healthcare, finance, and DevOps applications.
Earthly Reproducible Build Tool
Earthly combines Dockerfiles and Makefiles into reproducible, containerized builds. Learn how Earthly works, how to write Earthfiles, and when it replaces.
Energy-Efficient AI Infrastructure
Build sustainable AI infrastructure with energy-efficient GPU scheduling, green computing practices, carbon-aware workloads, and cooling optimization.
Explore topics
Browse more articles on the topics covered here.