DevOps & Containers
Updated for 2026

Docker Commands Cheatsheet 2026

Essential commands for managing containers, container images, persistent data volumes, networks, and Docker Compose environments.

Target Version Compatibility

Interactive Skill Mastery

Mark commands as learned to build your customized reference tracker. Retained locally in this browser.

Level:Novice
Command Mastery Progress0 of 26 Mastered (0%)

Containers

docker run -d -p 8080:80 --name my-app nginx
BeginnerBasics
Run a container in detached mode (-d), map host port 8080 to container port 80, and name it 'my-app'.

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 nginx

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker ps
BeginnerBasics
List currently running Docker containers on the host.

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 ps

Output Example

Console / Terminal
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-app
docker ps -a
BeginnerBasics
List all local containers, including running, paused, and stopped containers.

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 ps -a

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker stop <container>
BeginnerBasics
Gracefully stop a running container.

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker start <container>
BeginnerBasics
Start a stopped container.

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker rm <container>
BeginnerBasics
Delete a stopped container from local storage.

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker logs -f <container>
IntermediateDebugging
Stream and follow the console logs of a specific container in real-time.

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker exec -it <container> sh
BeginnerBasics
Execute an interactive (-it) shell inside a running container.

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> sh

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)

Images

docker build -t my-image:1.0 .
BeginnerBasics
Build a Docker image from a local Dockerfile in the current directory with tag 'my-image:1.0'.

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker images
BeginnerBasics
List all locally stored Docker 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 images

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker rmi <image_id>
BeginnerBasics
Remove a local image from storage (image must not be in use by any container).

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker pull <image_name>
IntermediateTeam Workflow
Download an image directly from Docker Hub register.

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

Console / Terminal
Status: Executed successfully (Docker engine active)
docker tag <source_image> <target_tag>
BeginnerBasics
Create a reference tag pointing to an existing image.

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

Console / Terminal
Status: Executed successfully (Docker engine active)

Volumes

docker volume create my-vol
BeginnerBasics
Create a named persistent volume to persist data outside container lifespans.

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-vol

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker volume ls
BeginnerBasics
List all local persistent Docker data 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 ls

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker volume rm my-vol
BeginnerBasics
Remove a specific named volume.

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-vol

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker volume prune
BeginnerBasics
Permanently delete all unused local volumes.

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 prune

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)

Networks

docker network create my-net
BeginnerBasics
Create a user-defined network for containers to communicate.

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-net

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker network ls
BeginnerBasics
List all networks configured in Docker on the host.

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 ls

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker network connect my-net <container>
BeginnerBasics
Connect a running container to a specific network.

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

Console / Terminal
Status: Executed successfully (Docker engine active)

Compose

docker compose up -d
BeginnerBasics
Parse docker-compose.yml and start all declared services in detached mode.

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 -d

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker compose down
BeginnerBasics
Stop and destroy all containers, networks, volumes, and images defined in the compose file.

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 down

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker compose logs -f
IntermediateDebugging
Stream combined service logs from your active compose deployment.

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 -f

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker compose ps
BeginnerBasics
Display running status of all container services belonging to active compose file.

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 ps

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)

System

docker system df
BeginnerBasics
Show summary of disk usage by containers, images, volumes, and cache.

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 df

Output Example

Console / Terminal
Status: Executed successfully (Docker engine active)
docker system prune -a --volumes
BeginnerBasics
Clean up unused data: delete stopped containers, dangling images, unused networks and volumes.

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 --volumes

Output Example

Console / Terminal
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

Error

Conflict: Container name already in use

Solution

Stop and delete the existing container: docker stop <name> && docker rm <name>, or execute with a unique name flag.

Error

Cannot connect to the Docker daemon. Is the docker daemon running?

Solution

Ensure Docker Desktop is launched, or start the background docker system service: sudo systemctl start docker.

Error

No space left on device (Docker system full)

Solution

Run 'docker system prune -a --volumes' to delete dangling images, stopped containers, and unused caches.

Error

Port already allocated

Solution

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).

Error

Vite/Dev Server not hot-reloading inside container

Solution

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.