Advertisement
Verified Partner
Enterprise Cloud Infrastructure, GPU Clusters & AI APIs
Deploy high-throughput inference and quant trading pipelines with ultra-low latency.
Explore Platform β†’

Docker Commands Cheatsheet: Images, Containers, Compose and Cleanup

The Docker commands used daily: build and manage images, run and debug containers, wire volumes and networks, drive Docker Compose, and clean up disk space safely.

πŸ§ͺ
Run & Edit this Code Live in Browser Zero setup required. Supports Python 3, modern JavaScript, and SQL.
β–Ά Run in Playground β†’

1. Images: Build, Tag and Share

An image is the packaged template; a container is a running instance of it. Keep images small and tagged by version, never only "latest".

CommandWhat it does
docker build -t myapp:1.0 .Build an image from the Dockerfile in this folder
docker imagesList local images and their sizes
docker pull nginx:1.27Download an image from a registry
docker tag myapp:1.0 registry.example.com/myapp:1.0Add another name/tag to an image
docker push registry.example.com/myapp:1.0Upload the image to the registry
docker rmi myapp:1.0Remove an image (containers using it must go first)
docker history myapp:1.0Show the layers an image is built from

2. Containers: Run, Inspect and Debug

The daily loop: start a container detached, watch its logs, jump inside when something looks wrong, and stop it cleanly.

CommandWhat it does
docker run -d --name web -p 8080:80 nginxRun detached, name it, publish host port 8080 to container port 80
docker ps / docker ps -aList running containers / all containers including stopped
docker logs -f webStream container logs (Ctrl+C detaches, container keeps running)
docker exec -it web shOpen a shell inside the running container
docker inspect webFull JSON detail: IP, mounts, env, state
docker stop web / docker start webStop gracefully (SIGTERM, then SIGKILL) / start again
docker rm webDelete a stopped container (add -f to force a running one)
docker statsLive CPU, memory and network per container
Advertisement
Verified Partner
Quantitative Trading Systems & 30 AI Business Blueprints
Build predictable monthly recurring revenue with retainers & automated bots.
View Blueprints β†’

3. Volumes and Networks

Containers are disposable; data is not. Anything that must survive a container replacement belongs in a volume, and services find each other by name on a shared network.

CODE SNIPPET
# Volumes: persistent data that outlives containers
docker volume create app-data
docker volume ls
docker run -d --name db -v app-data:/var/lib/postgresql/data postgres:16

# Bind mount: a host folder, ideal for local development
docker run -d --name dev -v $(pwd):/app -w /app node:20 npm run dev

# Networks: containers on the same network resolve each other by name
docker network create backend
docker network connect backend web
docker network ls
docker network inspect backend

4. Docker Compose and Cleanup

Compose declares the whole stack in one YAML file: services, ports, volumes, environment. One command builds and starts everything; the cleanup commands at the end keep Docker from eating your disk.

CODE SNIPPET
# docker-compose.yml (essentials)
services:
  api:
    build: .
    ports: ["8000:8000"]
    environment: ["DATABASE_URL=postgres://db:5432/app"]
    depends_on: [db]
  db:
    image: postgres:16
    volumes: ["db-data:/var/lib/postgresql/data"]
volumes:
  db-data:

docker compose up -d        # build + start the stack detached
docker compose ps           # status of the stack
docker compose logs -f api  # follow one service
docker compose exec api sh  # shell into a service
docker compose down         # stop and remove (add -v to also drop volumes)

# Cleanup: see usage first, then reclaim
docker system df
docker container prune      # stopped containers
docker image prune          # dangling images (-a removes all unused)
docker system prune         # stopped containers + unused networks + dangling images

πŸš€ Associated Learning Path & Monetization Blueprints

πŸ“š Comprehensive Pillar Guide

Docker Containerization and Production Deployments

From these commands to production: multi-stage builds, hardening and deployment patterns.

Read Full Guide β†’
πŸ’° Monetizable AI Blueprint

Private On-Premise AI

Deploy self-hosted AI stacks with Docker for clients who cannot use public clouds.

Read Blueprint β†’
πŸ“ˆ Topic Hub: DevOps & Cloud Infrastructure β†’

Need another cheat sheet?

We add new reference guides every week based on community requests.

Request a Cheatsheet β†’