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

推荐订阅源

S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
Jina AI
Jina AI
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
V
V2EX
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
B
Blog
博客园 - 叶小钗
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
A
About on SuperTechFans
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security 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 Cheat Sheet: Commands Every Developer Should Know
Ikegbo Ogoch · 2026-05-13 · via DEV Community

Introduction

Docker helps you package an application with everything it needs to run: code, dependencies, environment variables, and runtime settings. This cheat sheet covers the most useful Docker commands for daily development.


1. Check Docker Installation

docker --version
docker info
docker help

Enter fullscreen mode Exit fullscreen mode


2. Docker Images

List images

docker images

Enter fullscreen mode Exit fullscreen mode

Pull an image

docker pull nginx
docker pull python:3.12
docker pull node:20

Enter fullscreen mode Exit fullscreen mode

Remove an image

docker rmi image_name
docker rmi image_id

Enter fullscreen mode Exit fullscreen mode

Build an image from a Dockerfile

docker build -t my-app .

Enter fullscreen mode Exit fullscreen mode

Build with a specific Dockerfile

docker build -f Dockerfile.dev -t my-app-dev .

Enter fullscreen mode Exit fullscreen mode


3. Docker Containers

Run a container

docker run nginx

Enter fullscreen mode Exit fullscreen mode

Run container in detached mode

docker run -d nginx

Enter fullscreen mode Exit fullscreen mode

Run container with a name

docker run --name my-nginx nginx

Enter fullscreen mode Exit fullscreen mode

Run container and map ports

docker run -p 8080:80 nginx

Enter fullscreen mode Exit fullscreen mode

This maps port 8080 on your computer to port 80 inside the container.

Run container with environment variables

docker run -e APP_ENV=development my-app

Enter fullscreen mode Exit fullscreen mode

Run container interactively

docker run -it ubuntu bash

Enter fullscreen mode Exit fullscreen mode


4. List Containers

Running containers

docker ps

Enter fullscreen mode Exit fullscreen mode

All containers

docker ps -a

Enter fullscreen mode Exit fullscreen mode


5. Stop, Start, Restart Containers

docker stop container_name
docker start container_name
docker restart container_name

Enter fullscreen mode Exit fullscreen mode


6. Remove Containers

Remove one container

docker rm container_name

Enter fullscreen mode Exit fullscreen mode

Remove all stopped containers

docker container prune

Enter fullscreen mode Exit fullscreen mode


7. Logs and Debugging

View logs

docker logs container_name

Enter fullscreen mode Exit fullscreen mode

Follow logs live

docker logs -f container_name

Enter fullscreen mode Exit fullscreen mode

Enter a running container

docker exec -it container_name bash

Enter fullscreen mode Exit fullscreen mode

If bash is not available:

docker exec -it container_name sh

Enter fullscreen mode Exit fullscreen mode

Inspect container details

docker inspect container_name

Enter fullscreen mode Exit fullscreen mode


8. Volumes

Volumes help you persist data outside the container.

Create a volume

docker volume create my-volume

Enter fullscreen mode Exit fullscreen mode

List volumes

docker volume ls

Enter fullscreen mode Exit fullscreen mode

Use a volume

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

Enter fullscreen mode Exit fullscreen mode

Remove a volume

docker volume rm my-volume

Enter fullscreen mode Exit fullscreen mode

Remove unused volumes

docker volume prune

Enter fullscreen mode Exit fullscreen mode


9. Bind Mounts

Bind mounts connect a folder on your computer to a folder inside the container.

docker run -v $(pwd):/app my-app

Enter fullscreen mode Exit fullscreen mode

On Windows PowerShell:

docker run -v ${PWD}:/app my-app

Enter fullscreen mode Exit fullscreen mode


10. Networks

List networks

docker network ls

Enter fullscreen mode Exit fullscreen mode

Create a network

docker network create my-network

Enter fullscreen mode Exit fullscreen mode

Run container on a network

docker run --network my-network --name app my-app

Enter fullscreen mode Exit fullscreen mode

Remove a network

docker network rm my-network

Enter fullscreen mode Exit fullscreen mode


11. Dockerfile Example

FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["python", "app.py"]

Enter fullscreen mode Exit fullscreen mode


12. Docker Compose

Docker Compose helps you run multiple containers together.

Example docker-compose.yml

services:
  app:
    build: .
    ports:
      - "8000:8000"
    environment:
      - APP_ENV=development
    volumes:
      - .:/app

  database:
    image: postgres:16
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=mydb
    ports:
      - "5432:5432"

Enter fullscreen mode Exit fullscreen mode

Start services

docker compose up

Enter fullscreen mode Exit fullscreen mode

Start in detached mode

docker compose up -d

Enter fullscreen mode Exit fullscreen mode

Stop services

docker compose down

Enter fullscreen mode Exit fullscreen mode

Rebuild services

docker compose up --build

Enter fullscreen mode Exit fullscreen mode

View logs

docker compose logs
docker compose logs -f

Enter fullscreen mode Exit fullscreen mode


13. Cleaning Up Docker

Remove unused data

docker system prune

Enter fullscreen mode Exit fullscreen mode

Remove unused data including images

docker system prune -a

Enter fullscreen mode Exit fullscreen mode

Remove unused containers

docker container prune

Enter fullscreen mode Exit fullscreen mode

Remove unused images

docker image prune

Enter fullscreen mode Exit fullscreen mode

Remove unused volumes

docker volume prune

Enter fullscreen mode Exit fullscreen mode

Be careful with prune commands because they delete unused Docker resources.


14. Common Docker Commands Summary

docker build -t my-app .
docker run -p 8000:8000 my-app
docker ps
docker ps -a
docker stop container_name
docker start container_name
docker restart container_name
docker rm container_name
docker rmi image_name
docker logs -f container_name
docker exec -it container_name bash
docker system prune

Enter fullscreen mode Exit fullscreen mode


15. Useful Docker Compose Commands Summary

docker compose up
docker compose up -d
docker compose down
docker compose up --build
docker compose logs -f
docker compose ps
docker compose exec app bash

Enter fullscreen mode Exit fullscreen mode


Final Note

Docker is powerful because it makes your application easier to run, share, test, and deploy. Once you understand images, containers, volumes, networks, and Docker Compose, you can package almost any application into a reproducible environment.