the IT Hustle
工具实战手册关于
FundamentalsAI辅助2026-04-02•10 min 阅读

Docker in 10 Minutes: The Only Commands You Actually Need

作者: Salty Deprecated Software Engineer

✨ AI 辅助内容

本文由 AI 辅助创作,并经团队审核以确保准确性和质量。所有技术信息和示例均已验证。

Docker has a reputation for being complicated. It's not. The problem is that every tutorial starts with "Docker uses cgroups and namespaces to isolate processes in the Linux kernel" — and you close the tab before you learn anything useful.

Here's the truth: you need about 12 commands to use Docker for 95% of real work. The rest is edge cases and ops stuff you can Google when you need it.

This guide assumes you've installed Docker (docs.docker.com/get-docker) and have a terminal open. Let's go.

The Mental Model (30 Seconds)

Image = a blueprint (like a recipe)

Container = a running instance of that blueprint (like the cooked meal)

Docker Hub = a library of blueprints other people made (like a cookbook)

That's it. Everything else is details.

The 12 Commands You Need

1. docker pull — Download an Image

docker pull node:22

# Downloads the Node.js 22 image from Docker Hub

Like npm install but for entire environments.

2. docker run — Start a Container

docker run -it node:22 bash

# Starts a Node.js container and drops you into a shell

# -i = interactive, -t = terminal

3. docker run -d — Run in Background

docker run -d -p 3000:3000 --name myapp node:22

# -d = detached (runs in background)

# -p 3000:3000 = map port 3000 on your machine to 3000 in the container

# --name myapp = give it a name you can remember

4. docker ps — See What's Running

docker ps

# Shows all running containers

docker ps -a

# Shows ALL containers (including stopped)

5. docker stop / docker start — Control Containers

docker stop myapp

docker start myapp

6. docker logs — See What Happened

docker logs myapp

# Shows stdout/stderr from the container

docker logs -f myapp

# -f = follow (like tail -f)

7. docker exec — Run Commands Inside a Container

docker exec -it myapp bash

# Opens a shell inside a running container

# Great for debugging

8. docker build — Create Your Own Image

docker build -t my-app:v1 .

# -t = tag (name:version)

# . = use the Dockerfile in current directory

9. docker images — List Your Images

docker images

# Lists all images on your machine

10. docker rm / docker rmi — Clean Up

docker rm myapp

# Remove a stopped container

docker rmi node:22

# Remove an image

docker system prune

# Nuclear option: remove all unused containers, images, networks

11. docker-compose up — Multi-Container Apps

docker compose up -d

# Starts all services defined in docker-compose.yml

docker compose down

# Stops and removes everything

This is how you run a full stack locally — database, backend, frontend — with one command.

12. docker volume — Persist Your Data

docker run -v mydata:/app/data my-app

# -v = mount a volume so data survives container restarts

A Real-World Example: Postgres in 30 Seconds

# Start a Postgres database with one command:

docker run -d \

--name my-postgres \

-e POSTGRES_PASSWORD=secret \

-p 5432:5432 \

-v pgdata:/var/lib/postgresql/data \

postgres:16

# That's it. Connect at localhost:5432.

# Data persists because of the -v volume mount.

The Cheat Sheet

What You WantCommand
Download an imagedocker pull name:tag
Run interactivelydocker run -it name bash
Run in backgrounddocker run -d -p 3000:3000 name
See running containersdocker ps
Stop a containerdocker stop name
View logsdocker logs -f name
Shell into containerdocker exec -it name bash
Build your imagedocker build -t name:tag .
Clean everythingdocker system prune
Multi-container stackdocker compose up -d

The Bottom Line

Docker isn't hard — it's just poorly explained. The mental model is simple: images are blueprints, containers are running instances. 12 commands cover 95% of daily use. Everything else you learn as you need it.

Start with docker run -it node:22 bash. You'll be inside a Node.js environment in 10 seconds. From there, you're a Docker user.

New to the command line? Read our 10 Command Line Tools That Will 10x Your Productivity and learn Unix File Permissions Explained for Humans.

IT
Salty Deprecated Software Engineer

以 The IT Hustle 的编辑笔名写作——25 年以上笔记本维修技师、系统管理员、存储工程师和软件工程师的经验,如今用在 AI 智能体运维上。每篇文章发布前都经过人工审核,详见编辑准则。

我们的工具全部文章关于我们

获取最新资讯

第一时间了解新工具、博客文章和更新动态。无垃圾邮件。

生成专属防幻觉提示词

AI 提示词引擎采用专有技术,生成内置验证和矛盾测试的提示词。

免费试用 3 次 →

公司

  • 关于
  • 实战手册
  • AI 术语表
  • 关于作者
  • 联系我们

产品

  • 工具
  • 价格观察
  • 智能体运维
  • 编程
  • 设计
  • 运维
  • 效率
  • 营销
  • 商务

法律信息

  • 隐私政策
  • 服务条款
  • 免责声明
  • 编辑准则
  • 更正说明

© 2026 Salty Rantz LLC. 版权所有。

为在技术变革中前行的职场人打造。