All Articles

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.

DevOpsBoysMar 1, 20264 min read
Share:Tweet

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

bash
# 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-world

For 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.

bash
# Pull an image from Docker Hub
docker pull nginx
 
# List all local images
docker images

Containers

A container is a running instance of an image. You can run multiple containers from the same image.

bash
# 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.

dockerfile
# 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:

bash
# 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.

yaml
# 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:
bash
# Start all services
docker compose up -d
 
# View logs from all services
docker compose logs -f
 
# Stop all services
docker compose down

Best Practices

Use Official Base Images

dockerfile
# Recommended
FROM node:20-alpine
 
# Avoid doing this
FROM ubuntu:latest
RUN apt install nodejs

Minimize Image Layers

dockerfile
# 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

dockerfile
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

Essential Commands Reference

CommandDescription
docker build -t name .Build image from Dockerfile
docker run -d -p 8080:80 imageRun container in background
docker psList running containers
docker logs <id>View container logs
docker exec -it <id> shOpen shell inside container
docker stop <id>Gracefully stop a container
docker rm <id>Remove a stopped container
docker rmi imageRemove an image
docker system pruneClean up unused resources

What to Learn Next

  1. Docker Volumes — Persisting data beyond container lifecycle
  2. Docker Networks — Container-to-container communication
  3. Docker Registry (ECR/GCR) — Storing and distributing images
  4. 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.

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.

Newsletter

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

Comments