Docker Commands: Complete Cheat Sheet and Practical Guide (2026)

docker commands

Docker commands are the primary way to interact with Docker from the terminal. They allow you to build, run, manage, and troubleshoot containers and images efficiently. Mastering the most important Docker commands helps developers and system administrators work faster and avoid common mistakes.

This guide covers the essential Docker commands used in daily work, organised by category, with clear explanations and practical examples.

What Are Docker Commands?

Docker commands are instructions you type in the terminal to control the Docker Engine. They follow a simple structure:

docker [command] [options] [arguments]

Most daily tasks involve managing images, containers, volumes, networks, and system cleanup.

Essential Docker Commands by Category

1. Working with Images

2. Working with Containers

3. Useful Run Options

Common options used with docker run:

  • -d : Run in background
  • -it : Interactive mode with terminal
  • -p 8080:80 : Publish port (host:container)
  • -v /host/path:/container/path : Mount a volume
  • –name myapp : Assign a custom name
  • –rm : Automatically remove the container when it stops
  • -e KEY=value : Set environment variables

4. Managing Volumes

5. Managing Networks

6. System Cleanup Commands

Practical Examples

Run a simple Nginx container:

docker run -d -p 8080:80 –name web nginx

Build and run a custom image:

docker build -t myapp . docker run -d -p 3000:3000 –name myapp-container myapp

View logs of a container:

docker logs -f myapp-container

Open a shell inside a running container:

docker exec -it myapp-container bash

Clean up unused resources:

docker system prune -a

Best Practices for Using Docker Commands

  • Always prefer named containers (–name) for easier management
  • Use detached mode (-d) for long-running services
  • Clean up unused images and containers regularly to save disk space
  • Prefer official and verified images when possible
  • Use volumes for persistent data instead of storing data inside containers
  • Check logs with docker logs when troubleshooting
  • Avoid running containers as root when security is a concern

Common Mistakes to Avoid

  • Forgetting to map ports with -p
  • Not removing stopped containers, which consume space over time
  • Using docker rm on a running container without stopping it first
  • Losing data because no volume was mounted
  • Pulling large images without checking disk space
  • Running interactive containers without -it
  • Running containers without names

Key Takeaways

  • Docker commands are the main interface for managing containers and images
  • Daily work usually revolves around run, ps, logs, exec, and cleanup commands
  • Using options like -d, -p, -v, and –name makes containers more practical
  • Regular cleanup with docker system prune keeps the system healthy
  • Understanding the difference between images and containers is fundamental

Frequently Asked Questions

What is the difference between docker stop and docker kill?

docker stop sends a graceful shutdown signal. docker kill forces the container to stop immediately.

How do I remove all stopped containers at once?

Use docker container prune or docker rm $(docker ps -aq).

What does docker system prune -a do?

It removes all unused containers, images (both dangling and unused), and optionally volumes. Add –volumes if you also want to remove unused volumes.

How can I see the real-time logs of a container?

Use docker logs -f <container-name>.

What does –rm do?

It automatically deletes the container when it stops, which is useful for temporary containers.

Related Guides

Official resource: Official Docker Documentation

Comments

4 responses to “Docker Commands: Complete Cheat Sheet and Practical Guide (2026)”

  1. […] Docker Commands: Cheat Sheet & Guide […]

  2. […] Docker Commands: Cheat Sheet & Guide […]

  3. […] Docker Commands Cheat Sheet: Essential Commands for Everyday Use […]

  4. […] Docker Commands Cheat Sheet: Essential Commands for Everyday Use […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You might also like