Docker Commands Cheatsheet 2026
Essential commands for managing containers, container images, persistent data volumes, networks, and Docker Compose environments.
Interactive Skill Mastery
Mark commands as learned to build your customized reference tracker. Retained locally in this browser.
Containers
When to Use
When spinning up, shutting down, or managing live, sandboxed application containers.
Common Mistakes
Forgetting to expose container ports with the '-p' flag (e.g., -p 8080:80), making services inaccessible from host.
Shortcut / Pro-Tip
Use 'docker run --rm' to automatically delete the container when it exits.Example
docker run -d -p 8080:80 --name my-app nginxOutput Example
Status: Executed successfully (Docker engine active)When to Use
When inspecting the server to verify which Docker containers are currently active, running, and listening on active ports.
Common Mistakes
Assuming a container doesn't exist because it isn't listed here. If a container crashed or exited, it will only show up in 'docker ps -a'.
Shortcut / Pro-Tip
Press Ctrl+C to exit any streaming or interactive container terminals.Example
docker psOutput Example
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b9d7a1c2e4f nginx "/docker-entrypoint.…" 5 minutes ago Up 5 minutes 0.0.0.0:8080->80/tcp my-appWhen to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker ps -aOutput Example
Status: Executed successfully (Docker engine active)When to Use
When spinning up, shutting down, or managing live, sandboxed application containers.
Common Mistakes
Forgetting to expose container ports with the '-p' flag (e.g., -p 8080:80), making services inaccessible from host.
Shortcut / Pro-Tip
Use 'docker run --rm' to automatically delete the container when it exits.Example
docker stop <container>Output Example
Status: Executed successfully (Docker engine active)When to Use
When spinning up, shutting down, or managing live, sandboxed application containers.
Common Mistakes
Forgetting to expose container ports with the '-p' flag (e.g., -p 8080:80), making services inaccessible from host.
Shortcut / Pro-Tip
Use 'docker run --rm' to automatically delete the container when it exits.Example
docker start <container>Output Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker rm <container>Output Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker logs -f <container>Output Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker exec -it <container> shOutput Example
Status: Executed successfully (Docker engine active)Images
When to Use
When compiling or listing reusable custom container layers from local Dockerfile blueprints.
Common Mistakes
Including heavy development dependencies or node_modules in your build context (configure a .dockerignore file!).
Shortcut / Pro-Tip
Docker caches layers; make sure your COPY commands are placed as late as possible in Dockerfiles to speed up rebuilds.Example
docker build -t my-image:1.0 .Output Example
Status: Executed successfully (Docker engine active)When to Use
When compiling or listing reusable custom container layers from local Dockerfile blueprints.
Common Mistakes
Including heavy development dependencies or node_modules in your build context (configure a .dockerignore file!).
Shortcut / Pro-Tip
Docker caches layers; make sure your COPY commands are placed as late as possible in Dockerfiles to speed up rebuilds.Example
docker imagesOutput Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker rmi <image_id>Output Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker pull <image_name>Output Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker tag <source_image> <target_tag>Output Example
Status: Executed successfully (Docker engine active)Volumes
When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker volume create my-volOutput Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker volume lsOutput Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker volume rm my-volOutput Example
Status: Executed successfully (Docker engine active)When to Use
When spinning up, shutting down, or managing live, sandboxed application containers.
Common Mistakes
Forgetting to expose container ports with the '-p' flag (e.g., -p 8080:80), making services inaccessible from host.
Shortcut / Pro-Tip
Use 'docker run --rm' to automatically delete the container when it exits.Example
docker volume pruneOutput Example
Status: Executed successfully (Docker engine active)Networks
When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker network create my-netOutput Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker network lsOutput Example
Status: Executed successfully (Docker engine active)When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker network connect my-net <container>Output Example
Status: Executed successfully (Docker engine active)Compose
When to Use
When bootstrapping, configuring, or destroying multi-container service stacks linked with isolated networks (e.g. App + DB).
Common Mistakes
Editing docker-compose.yml with tab spacing instead of two spaces, which breaks YAML formatting.
Shortcut / Pro-Tip
Run 'docker compose up -d' to start the containers silently in the background.Example
docker compose up -dOutput Example
Status: Executed successfully (Docker engine active)When to Use
When bootstrapping, configuring, or destroying multi-container service stacks linked with isolated networks (e.g. App + DB).
Common Mistakes
Editing docker-compose.yml with tab spacing instead of two spaces, which breaks YAML formatting.
Shortcut / Pro-Tip
Run 'docker compose up -d' to start the containers silently in the background.Example
docker compose downOutput Example
Status: Executed successfully (Docker engine active)When to Use
When bootstrapping, configuring, or destroying multi-container service stacks linked with isolated networks (e.g. App + DB).
Common Mistakes
Editing docker-compose.yml with tab spacing instead of two spaces, which breaks YAML formatting.
Shortcut / Pro-Tip
Run 'docker compose up -d' to start the containers silently in the background.Example
docker compose logs -fOutput Example
Status: Executed successfully (Docker engine active)When to Use
When bootstrapping, configuring, or destroying multi-container service stacks linked with isolated networks (e.g. App + DB).
Common Mistakes
Editing docker-compose.yml with tab spacing instead of two spaces, which breaks YAML formatting.
Shortcut / Pro-Tip
Run 'docker compose up -d' to start the containers silently in the background.Example
docker compose psOutput Example
Status: Executed successfully (Docker engine active)System
When to Use
Use when you want to interact with Docker containers, build secure container images, or configure persistent networks and volumes.
Common Mistakes
Assuming changes inside running containers are saved permanently without mounting volume points.
Shortcut / Pro-Tip
Press Ctrl+D to exit interactive container shell streams.Example
docker system dfOutput Example
Status: Executed successfully (Docker engine active)When to Use
When spinning up, shutting down, or managing live, sandboxed application containers.
Common Mistakes
Forgetting to expose container ports with the '-p' flag (e.g., -p 8080:80), making services inaccessible from host.
Shortcut / Pro-Tip
Use 'docker run --rm' to automatically delete the container when it exits.Example
docker system prune -a --volumesOutput Example
Status: Executed successfully (Docker engine active)Docker Commands Best Practices
1Use Multi-Stage Builds
Use multi-stage Dockerfiles to build your application in intermediate containers, and copy only the final assets to minimize image sizes.
2Leverage Docker Build Cache
Order commands in your Dockerfile so that static layers (like installing dependencies) are placed before files that change frequently.
3Avoid Storing Secrets in Images
Never hardcode passwords or API keys inside Dockerfiles. Pass them dynamically using environment variables or Docker Secrets.
4Run Containers as Non-Root Users
Configure a custom USER inside your Dockerfiles to reduce vulnerability threats if containers are compromised.
5Use Explicit Version Tags
Avoid using the 'latest' image tag in production. Use specific semantic version tags (e.g. node:18.16-alpine) for deterministic builds.
Common Docker Commands Errors & Solutions
Conflict: Container name already in use
Stop and delete the existing container: docker stop <name> && docker rm <name>, or execute with a unique name flag.
Cannot connect to the Docker daemon. Is the docker daemon running?
Ensure Docker Desktop is launched, or start the background docker system service: sudo systemctl start docker.
No space left on device (Docker system full)
Run 'docker system prune -a --volumes' to delete dangling images, stopped containers, and unused caches.
Port already allocated
The host port is in use by another service. Modify your port mapping flag (e.g. map to -p 8081:80 instead of -p 80:80).
Vite/Dev Server not hot-reloading inside container
Ensure your Vite dev config has watch polling enabled: server: { watch: { usePolling: true } }.
Common Docker Commands Interview Questions
Q1What is the difference between a Docker Image and a Docker Container?
A Docker Image is a read-only, static package blueprint containing the source code, libraries, and dependencies. A Docker Container is a live, running, isolated instance created from that image.
Q2What is the difference between COPY and ADD in a Dockerfile?
COPY simply transfers local files from the host machine to the container. ADD has extra capabilities: it can extract compressed archives (TAR) and download assets from remote URLs.
Q3What is a Docker Volume and why is it used?
A volume is a persistent storage directory managed by Docker outside the container's union file system. It is used to save data permanently so it survives container restarts and updates.
Q4What is Docker Compose and what problem does it solve?
Docker Compose is a utility used to define and manage multi-container applications. It lets you configure, spin up, and coordinate multiple services (App, DB, Cache) using a single YAML file.
Q5How do you minimize the size of a Docker Image?
Use multi-stage builds, choose lightweight base images (like Alpine Linux), combine RUN instructions to reduce layers, configure a .dockerignore file, and clean package manager caches.
Related Resources
REST API Tester
Test API routes and endpoints directly in your browser with full request controls.
JSON Formatter & Validator
Beautify, validate, and minify JSON structures instantly.
Best Free Online Developer Tools
An expert review of must-have online utilities for developers.
Git Cheatsheet
Essential command reference for local and remote version control repositories.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com