惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
罗磊的独立博客
Last Week in AI
Last Week in AI
B
Blog
IT之家
IT之家
S
SegmentFault 最新的问题
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - 聂微东
U
Unit 42
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
MyScale Blog
MyScale Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Docker for Beginners: From Zero to Running a Full Stack L...
TrackStack · 2026-04-24 · via DEV Community

TrackStack

"Install PostgreSQL, then Redis, then Elasticsearch, configure these 12 environment variables, make sure you're on Node 20 not 18, and oh — the tests need Python 3.11."

Sound like your onboarding doc? Here's the Docker version: docker compose up. Done. New dev writes code in 15 minutes.

The 3 Commands That Cover 80% of Docker

You don't need to learn everything. Start here:

# Run any service instantly
docker run -d -p 8080:80 nginx:latest

# Build your own app into an image
docker build -t my-app:1.0 .

# Start your entire stack (app + db + cache)
docker compose up -d

Enter fullscreen mode Exit fullscreen mode

Open http://localhost:8080 after the first command — you'll see Nginx running. No install, no config, no conflicts.

Your First Dockerfile (Copy This)

A Dockerfile is a recipe for turning your code into a container. Here's one for a Node.js app:

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

Enter fullscreen mode Exit fullscreen mode

The trick: COPY package*.json before COPY . . means Docker caches your npm ci step. Change your code? Rebuild takes 2 seconds instead of 30.

Build it: docker build -t my-app:1.0 .
Run it: docker run -d -p 3000:3000 my-app:1.0

For Python/Flask, same pattern:

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]

Enter fullscreen mode Exit fullscreen mode

Docker Compose: The Real Power

Your app needs a database and Redis? One file, one command:

version: "3.9"
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/mydb
      REDIS_URL: redis://cache:6379
    depends_on:
      - db
      - cache

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    volumes:
      - pgdata:/var/lib/postgresql/data

  cache:
    image: redis:7-alpine

volumes:
  pgdata:

Enter fullscreen mode Exit fullscreen mode

docker compose up -d        # start everything
docker compose down          # stop everything
docker compose up -d --build # rebuild after code changes
docker compose down -v       # stop + delete database data

Enter fullscreen mode Exit fullscreen mode

The pgdata volume means your database survives container restarts. Remove it with -v only when you want a fresh start.

The 10 Commands Cheat Sheet

Command What It Does
docker run -d -p 8080:80 nginx Run a container
docker build -t app:1.0 . Build an image
docker ps List running containers
docker ps -a List all containers
docker logs -f my-app Follow container logs
docker exec -it my-app sh Shell into a container
docker stop my-app Stop a container
docker rm my-app Remove a container
docker compose up -d Start all services
docker compose down Stop all services

Before You Deploy: Quick Checklist

  • ✅ Using alpine or slim base image (not the 1 GB default)
  • .dockerignore excludes node_modules, .git, .env
  • ✅ Container runs as non-root (USER node)
  • ✅ Secrets passed via environment, never hardcoded
  • ✅ Volumes configured for database data
  • ✅ Health check added: HEALTHCHECK CMD curl -f http://localhost:3000/health || exit 1
  • ✅ Tested with docker compose up on a clean machine

Common Gotchas

"My container exits immediately." Your app probably crashes on startup. Check logs: docker logs my-app. Most common cause: missing environment variable that's set on your machine but not in the container.

"Database is empty after restart." You forgot the volume. Without volumes: in docker-compose.yml, data lives inside the container and dies with it.

"Port already in use." Something else is running on that port. Either stop it or change the host port: -p 3001:3000 maps host port 3001 to container port 3000.

"Image is 1.2 GB." Use node:20-alpine instead of node:20. Add .dockerignore. Use multi-stage builds for compiled languages. Typical reduction: 1 GB → 100 MB.


📖 The full guide covers installation walkthroughs for Windows/macOS/Linux, Python Dockerfile examples, Docker Desktop licensing (free vs paid), multi-stage builds, and a production-readiness checklist.

Read the full article on trackstack.tech →