ByteVerse
HomeBlogCategoriesAboutContact
Search...
Read Blog
ByteVerse

No-fluff guides on AI tools, coding, and productivity. We test everything before we write about it.

Quick Links

  • Home
  • Blog
  • Categories
  • About
  • Contact

Categories

  • AI Tools
  • Tech Guides
  • Productivity
  • Coding
  • Software Reviews

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer
  • Contact

© 2026 ByteVerse. All rights reserved.

contact@byteverse.fyi
HomeBlogTech Guides
Tech Guides

Docker for Beginners 2026: Complete Getting Started Guide

Learn Docker from scratch - containers, images, Docker Compose, and deployment explained step by step for beginners.

B
ByteVerse
May 21, 202613 min read
Docker for Beginners 2026: Complete Getting Started Guide cover image

Docker solves the "it works on my machine" problem. It packages your application with all its dependencies into a container that runs the same everywhere - your laptop, your teammate's laptop, and the production server.

This guide teaches you Docker from zero, step by step.

Docker for beginners 2026 getting started guide
Docker for beginners 2026

Why Learn Docker in 2026?

  • Industry standard - 83% of organizations use containers in production
  • Required in job postings - most backend and DevOps roles require Docker knowledge
  • Consistent environments - no more "works on my machine" issues
  • Easy deployment - deploy to any cloud with one command
  • Microservices - Docker is the foundation of modern architecture
  • Learning DevOps - Docker is the first step toward Kubernetes

What Is Docker?

Docker creates containers - lightweight, isolated environments that package your app with everything it needs to run.

Without Docker:

  • "Install Node.js 20, PostgreSQL 15, Redis 7, set these 20 environment variables, run these 5 commands..."
  • Works on your machine but crashes on your teammate's
  • Production server has different versions of everything

With Docker:

  • One Dockerfile describes everything your app needs
  • docker compose up starts everything with one command
  • Same environment everywhere - development, testing, production

Key Concepts

Images vs Containers

ConceptAnalogyWhat It Is
ImageRecipeBlueprint with instructions to build your environment
ContainerThe mealA running instance of an image
  • An image is a read-only template (like a class in programming)
  • A container is a running instance of an image (like an object)
  • You can run multiple containers from the same image

Dockerfile

A Dockerfile is a text file with instructions to build an image:

Code
# Start from Node.js base image
FROM node:20-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy application code
COPY . .

# Build the application
RUN npm run build

# Expose port 3000
EXPOSE 3000

# Start command
CMD ["npm", "start"]

What each instruction does:

  • FROM - base image to start from (like an OS with tools pre-installed)
  • WORKDIR - set the working directory inside the container
  • COPY - copy files from your machine into the container
  • RUN - execute a command during image build
  • EXPOSE - document which port the app listens on
  • CMD - the command to run when the container starts

Step 1: Install Docker

Windows/Mac: Download Docker Desktop from docker.com

Linux:

Code
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Verify installation:

Code
docker --version
# Docker version 27.x.x

docker run hello-world
# Should print "Hello from Docker!"

Step 2: Your First Container

Run an Existing Image

Code
# Run an Nginx web server
docker run -d -p 8080:80 nginx

# -d = run in background (detached)
# -p 8080:80 = map your port 8080 to container's port 80

Open http://localhost:8080 - you will see the Nginx welcome page!

Manage Containers

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

# View container logs
docker logs <container_id>

# Execute a command inside a container
docker exec -it <container_id> /bin/sh

Step 3: Build Your Own Image

Example: Dockerize a Node.js App

  1. Create a simple app:
Code
// server.js
const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from Docker!');
});
server.listen(3000, () => console.log('Server running on port 3000'));
  1. Create a Dockerfile:
Code
FROM node:20-alpine
WORKDIR /app
COPY server.js .
EXPOSE 3000
CMD ["node", "server.js"]
  1. Build and run:
Code
# Build the image
docker build -t my-app .

# Run a container from the image
docker run -d -p 3000:3000 my-app

# Test it
curl http://localhost:3000
# Hello from Docker!

.dockerignore

Like .gitignore, this file tells Docker what NOT to copy:

Code
node_modules
.git
.env
.next
dist
*.log

Always include node_modules - dependencies should be installed fresh inside the container.

Docker container workflow diagram
Docker container workflow 2026

Step 4: Docker Compose

Docker Compose lets you run multiple containers together. Most real apps need a web server + database + cache.

docker-compose.yml Example

Code
version: '3.8'

services:
  # Your web application
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://user:password@db:5432/myapp
      - REDIS_URL=redis://cache:6379
    depends_on:
      - db
      - cache

  # PostgreSQL database
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: myapp
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  # Redis cache
  cache:
    image: redis:7-alpine
    ports:
      - "6379:6379"

volumes:
  pgdata:

Docker Compose Commands

Code
# Start all services
docker compose up

# Start in background
docker compose up -d

# Stop all services
docker compose down

# Rebuild after code changes
docker compose up --build

# View logs
docker compose logs -f

# Run a command in a service
docker compose exec web sh

One command to start your entire app - web server, database, and cache. Every team member runs the same setup.

Step 5: Volumes (Persistent Data)

Containers are ephemeral - when you remove a container, its data is gone. Volumes persist data outside the container.

Types of volumes:

  • Named volumes - Docker manages the storage (best for databases)
  • Bind mounts - map a host directory to a container directory (best for development)
Code
# Named volume (database data persists)
volumes:
  - pgdata:/var/lib/postgresql/data

# Bind mount (live code reloading for development)
volumes:
  - ./src:/app/src

Step 6: Docker for Development

Hot Reloading Setup

For development, mount your source code so changes appear instantly:

Code
# docker-compose.dev.yml
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "3000:3000"
    volumes:
      - .:/app           # Mount entire project
      - /app/node_modules # Prevent overwriting node_modules
    environment:
      - NODE_ENV=development
Code
# Dockerfile.dev
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]

Step 7: Deploying with Docker

Deploy to Any Cloud

Docker containers run on every cloud platform:

  • Railway - git push deploys with auto-detection
  • Fly.io - fly deploy from Dockerfile
  • AWS ECS - managed container service
  • Google Cloud Run - serverless containers
  • DigitalOcean App Platform - simple container hosting

Production Dockerfile (Multi-Stage Build)

Code
# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

# Stage 2: Production (smaller image)
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package.json ./
EXPOSE 3000
CMD ["npm", "start"]

Multi-stage builds create smaller production images by only including what is needed to run (not build tools, dev dependencies, etc.).

Essential Docker Commands Cheat Sheet

CommandWhat It Does
docker build -t name .Build image from Dockerfile
docker run -d -p 3000:3000 nameRun container
docker psList running containers
docker stop idStop container
docker rm idRemove container
docker imagesList images
docker rmi nameRemove image
docker logs idView logs
docker exec -it id shShell into container
docker compose up -dStart all services
docker compose downStop all services
docker compose logs -fFollow logs
docker system pruneClean unused resources

Common Mistakes Beginners Make

  1. Not using .dockerignore - copies node_modules into the image (huge, slow)
  2. Running as root - add USER node in Dockerfile for security
  3. Not using multi-stage builds - production images are unnecessarily large
  4. Storing secrets in Dockerfile - use environment variables or secrets management
  5. Not using volumes for databases - data disappears when container is removed
  6. Using latest tag - always pin specific versions (node:20-alpine, not node:latest)
  7. Ignoring layer caching - put COPY package.json before COPY . for faster builds
  8. Not cleaning up - run docker system prune regularly to free disk space

Related ByteVerse guides

Next, read Next.js 16 Deployment Guide 2026, JavaScript Roadmap 2026, How to Learn Programming 2026, and Website Speed Optimization 2026 to explore more.

Running Docker on Windows? Set up WSL 2 first - Docker Desktop uses it as the backend and performance is significantly better.

Frequently Asked Questions

Is Docker hard to learn?

The basics (build, run, docker-compose) take 2-3 hours to learn. Understanding images, containers, volumes, and networking takes a few days of practice. Docker is easier than most people expect - the concepts are intuitive once you start using them.

Do I need Docker for web development?

Not strictly necessary, but highly recommended. Docker ensures every team member has the same development environment. It eliminates "works on my machine" problems and makes onboarding new developers instant.

Docker vs virtual machines - what is the difference?

Docker containers share the host OS kernel, making them lightweight (MBs) and fast to start (seconds). Virtual machines include a full OS, making them heavy (GBs) and slow to start (minutes). Use Docker for applications, VMs for running different operating systems.

How much RAM does Docker need?

Docker Desktop recommends 4GB RAM minimum. Each container uses only what the app inside it needs - a Node.js app might use 50-200MB. A typical development setup with web server + database + cache uses 500MB-1GB total.

Should I learn Docker or Kubernetes first?

Docker first, always. Kubernetes orchestrates Docker containers at scale. You need to understand Docker containers before Kubernetes makes sense. Learn Docker → Docker Compose → then Kubernetes when you need to manage many containers.

Is Docker free?

Docker Engine is free and open source. Docker Desktop is free for personal use, education, and small businesses (under 250 employees). Large enterprises need a Docker Business subscription ($24/user/month).

Share this article

Written by

ByteVerseView all posts

You Might Also Like

All Posts
Linux and WSL Setup Guide 2026: Complete Environment for Windows Developers

Linux and WSL Setup Guide 2026: Complete Environment for Windows Developers

May 21, 202612 min read
How to Learn Programming in 2026: Complete Beginner Roadmap

How to Learn Programming in 2026: Complete Beginner Roadmap

May 21, 20268 min read
Online Security Checklist 2026: Passkeys and 2FA

Online Security Checklist 2026: Passkeys and 2FA

May 20, 202610 min read