Docker Complete Beginners Guide — Everything You Need to Know
What is Docker, why engineers use it, and how to get started with containers from scratch. A practical, no-fluff guide.
What is Docker?
Docker is a containerization platform that packages your application along with all its dependencies into a single portable unit called a container.
Think of a shipping container — you pack anything inside and ship it anywhere in the world. The same concept applies to software: pack your application and its environment, run it anywhere consistently.
Simple definition: A Docker container is a lightweight, standalone, executable package that includes everything needed to run an application — code, runtime, system tools, libraries, and settings.
Why Do Engineers Use Docker?
The classic problem in software development: "It works on my machine!" — Docker permanently solves this.
- Consistency — Dev, staging, and production all run identical environments
- Isolation — Applications don't interfere with each other
- Portability — Runs on your laptop, a cloud server, or anywhere else
- Speed — Containers start in milliseconds vs. minutes for VMs
- Efficiency — Multiple containers share the same OS kernel
Installation
# Ubuntu / Debian
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
# Verify the installation
docker --version
# Docker version 25.0.0, build abc1234
docker run hello-worldFor Mac or Windows, download Docker Desktop — it includes everything you need.
Core Concepts
Images
A Docker image is a read-only template used to create containers. Think of it as a blueprint.
# Pull an image from Docker Hub
docker pull nginx
# List all local images
docker imagesContainers
A container is a running instance of an image. You can run multiple containers from the same image.
# Run a container in background (-d = detached mode)
docker run -d -p 80:80 nginx
# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# Stop a container
docker stop <container_id>
# Remove a container
docker rm <container_id>Writing Your First Dockerfile
A Dockerfile is a text file containing instructions to build a Docker image.
# Start from an official base image
FROM node:20-alpine
# Set the working directory inside the container
WORKDIR /app
# Copy dependency files first (layer caching optimization)
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the source code
COPY . .
# Expose the application port
EXPOSE 3000
# Command to start the application
CMD ["node", "server.js"]Build and run your image:
# Build the image
docker build -t my-app:v1 .
# Run a container from the image
docker run -d -p 3000:3000 my-app:v1
# View logs
docker logs <container_id>Docker Compose — Multiple Services Together
Real applications typically need multiple services: a web server, database, and cache. Docker Compose manages all of them together.
# docker-compose.yml
version: '3.8'
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
- redis
environment:
- DATABASE_URL=postgresql://user:password@db:5432/myapp
- REDIS_URL=redis://redis:6379
db:
image: postgres:16-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=myapp
redis:
image: redis:7-alpine
volumes:
postgres_data:# Start all services
docker compose up -d
# View logs from all services
docker compose logs -f
# Stop all services
docker compose downBest Practices
Use Official Base Images
# Recommended
FROM node:20-alpine
# Avoid doing this
FROM ubuntu:latest
RUN apt install nodejsMinimize Image Layers
# Bad — creates 3 separate layers
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get clean
# Good — single layer, smaller image
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*Always Use .dockerignore
node_modules
.git
*.log
.env
dist
Run as Non-Root User
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuserEssential Commands Reference
| Command | Description |
|---|---|
docker build -t name . | Build image from Dockerfile |
docker run -d -p 8080:80 image | Run container in background |
docker ps | List running containers |
docker logs <id> | View container logs |
docker exec -it <id> sh | Open shell inside container |
docker stop <id> | Gracefully stop a container |
docker rm <id> | Remove a stopped container |
docker rmi image | Remove an image |
docker system prune | Clean up unused resources |
What to Learn Next
- Docker Volumes — Persisting data beyond container lifecycle
- Docker Networks — Container-to-container communication
- Docker Registry (ECR/GCR) — Storing and distributing images
- Kubernetes — Orchestrating containers at scale
Docker is the foundation of modern DevOps. Once you understand containers, everything else — Kubernetes, CI/CD pipelines, microservices — starts to fall into place.
Recommended Course
If you want to go from zero to job-ready with Docker through hands-on labs — not just videos — KodeKloud is the best platform for it. Their Docker and Kubernetes courses come with real browser-based terminal environments where you practice on actual clusters, not local mocks.
Stay ahead of the curve
Get the latest DevOps, Kubernetes, AWS, and AI/ML guides delivered straight to your inbox. No spam — just practical engineering content.
Related Articles
Docker Compose Complete Guide 2026: From Zero to Production
Master Docker Compose in 2026. Learn how to write docker-compose.yml files, manage volumes, networks, environment variables, health checks, and run multi-container apps the right way.
Why Your Docker Container Keeps Restarting (and How to Fix It)
CrashLoopBackOff, OOMKilled, exit code 1, exit code 137 — Docker containers restart for specific, diagnosable reasons. Here is how to identify the exact cause and fix it in minutes.
Docker Security Best Practices — Production Checklist (2026)
A complete Docker security checklist for production. Cover image hardening, runtime security, secrets management, network isolation, and scanning — with real examples.