Skip to main content
ContainersBeginner

Docker for Beginners: A Complete Getting Started Guide

Learn the fundamentals of Docker — from installation and your first container to Dockerfiles, Compose, and production best practices.

N
Neeraj Jha
·Updated September 4, 2026·8 min read·155 views
Docker for Beginners: A Complete Getting Started Guide

Docker for Beginners: A Complete Getting Started Guide

Docker has revolutionized how we build, ship, and run applications. Instead of worrying about environment differences between development and production, Docker lets you package everything your app needs into a portable container.

What Is Docker?

Docker is a platform that uses OS-level virtualization to deliver software in packages called containers. Containers are lightweight, standalone, and include everything needed to run a piece of software: code, runtime, libraries, and system tools.

Containers vs Virtual Machines

FeatureContainersVirtual Machines
Startup timeSecondsMinutes
SizeMegabytesGigabytes
IsolationProcess-levelFull OS
PerformanceNear-nativeOverhead from hypervisor

Installing Docker

On macOS or Windows, install Docker Desktop from docker.com. On Linux:

bash
# Ubuntu / Debian
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker

# Add your user to the docker group
sudo usermod -aG docker $USER

Your First Container

bash
# Pull and run the official Nginx image
docker run -d -p 8080:80 --name my-nginx nginx

# Verify it's running
docker ps

# Check logs
docker logs my-nginx

# Stop and remove
docker stop my-nginx
docker rm my-nginx

Writing a Dockerfile

A Dockerfile defines how to build your image. Here's one for a Node.js app:

dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Build and run it:

bash
docker build -t my-node-app .
docker run -d -p 3000:3000 my-node-app

Essential Docker Commands

  • docker images — list local images
  • docker ps -a — list all containers (including stopped)
  • docker exec -it <container> sh — shell into a running container
  • docker volume ls — list volumes for persistent data
  • docker network ls — list networks

Docker Compose

For multi-container setups, use Docker Compose:

yaml
version: "3.9"
services:
  web:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: myapp
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

Run with docker compose up -d.

Best Practices

  • Use multi-stage builds to keep images small
  • Never run containers as root in production
  • Use .dockerignore to exclude unnecessary files
  • Pin image versions (e.g., node:20-alpine, not node:latest)
  • One process per container

Docker is the foundation of modern DevOps. Master these basics and you're ready to tackle orchestration with Kubernetes.

Tagged with

Enjoyed this article?

Get more DevOps insights delivered to your inbox.

Get new posts by email

Subscribe to get an email when a new blog post is published. Skip anytime.

No spam, unsubscribe anytime.

N

Written by

Neeraj Jha

Platform administrator and lead writer.

View all posts

Discussion

1 comment

Sign in to join the conversation.

P
Priya Kapoor6mo ago

This is exactly what I needed to get started with Docker. The Compose example is really helpful!

N
Neeraj Jha6mo ago

Glad it helped! Multi-stage builds are a game-changer for keeping images small.

Share: