🐳 Neel’s Notebook • Docker Journey

From Zero ▶ Docker Hero

A crisp, practical guide to containers—focused on doing. Save time with copy‑ready commands, simple examples, and fixes to real errors.

Learning Status
Active
Projects
3 mini / 1 full
Core Topics
Images • Compose • Volumes
Last Updated

Quickstart (teach like I’m 2 🐣)

Install Docker Desktop. Open it. If the whale smiles, you’re good.
Run a container: docker run hello-world
Pull an image: docker pull nginx
Start nginx: docker run -p 8080:80 nginx → open localhost:8080
Stop & remove: docker ps → copy CONTAINER ID → docker stop <id> && docker rm <id>

Tip: Map ports host:container. If 8080 is busy, map 9090:80.

Learning Roadmap

Track progress. Your checks save to your browser (localStorage).

Goal: Build → Run → Persist → Network → Compose → Publish

Docker Commands Cheat Sheet

Filter by topic and click to copy commands. Search live.

Example: Dockerfile (Node.js)

Small, production‑ready-ish image with caching and non‑root user.

# syntax=docker/dockerfile:1
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production PORT=8080
COPY --from=deps /app/node_modules ./node_modules
COPY . .
USER node
EXPOSE 8080
CMD ["node","server.js"]

Tip: Use multi‑stage builds to keep runtime images small.

Example: docker‑compose.yml

Web + DB with a named volume and network.

services:
  web:
    build: .
    ports:
      - "8080:8080"
    environment:
      - DB_HOST=db
    depends_on:
      - db
    networks: [appnet]

  db:
    image: postgres:16
    environment:
      - POSTGRES_PASSWORD=changeme
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks: [appnet]

volumes:
  pgdata:

networks:
  appnet:

Remember to secure secrets (use env files, secret managers).

Common Errors & Fixes

Port already in use (EADDRINUSE)

Another process is listening on that host port. Choose a free port or stop the process.

# find a free port quickly
# try 9090 instead of 8080
$ docker run -p 9090:80 nginx
“permission denied” writing files from container

On Linux, mount options or user mismatch cause this. Run as a user that owns the volume path or adjust permissions.

$ docker run -u $(id -u):$(id -g) -v $(pwd)/data:/data app
Container exits immediately

The main process ended. Use a long‑running command (server) or tail -f during debugging.

$ docker run yourapp tail -f /dev/null
Can’t connect to service containers

Put containers on the same user‑defined network, then use the service name as the hostname.

$ docker network create appnet
$ docker run --network appnet --name api yourapi
$ docker run --network appnet curlimages/curl curl http://api:8080/health

Glossary (fast intuition)

Memory Hook:

Image = Recipe • Container = Cooked dish • Volume = Fridge • Network = Dining table

Study Plan (weekend sprint)

  1. Rebuild Dockerfile twice with caching in mind.
  2. Convert a “works on my machine” app to Compose (web + db).
  3. Use a bind mount to live‑reload code in dev.
  4. Push image to a private repo on Docker Hub.
  5. Write a one‑page post: “What surprised me about Docker.”

Handy Links

Use rate‑limited pulls wisely—authenticate with Docker Hub.