Docker Commands Cheat Sheet: 50 Essential Commands Every Developer Must Know in 2025

Docker has revolutionized how developers build, ship, and run applications. Whether you’re a beginner starting your containerization journey or an experienced developer looking for a quick reference, this comprehensive Docker commands cheat sheet covers the 50 most frequently used commands that every developer should master.

Docker Commands Cheat Sheet 50 Essential Commands - thedevopstooling

What is Docker?

Docker is a containerization platform that enables developers to package applications and their dependencies into lightweight, portable containers. These containers can run consistently across different environments, from development laptops to production servers.

Docker Commands Cheat Sheet

Basic Docker Commands

1. Check Docker Version

docker --version

Purpose: Displays the installed Docker version Example Output: Docker version 24.0.7, build afdd53b

2. Get Docker System Information

docker info

Use Case: Shows comprehensive system information including containers, images, and storage drivers

3. Display Docker Help

docker --help

When to Use: Quick reference for available Docker commands and options

4. Search Docker Hub for Images

docker search <image_name>

Example: docker search nginx Purpose: Find official and community images on Docker Hub

5. Login to Docker Registry

docker login

Required For: Pushing images to Docker Hub or private registries

Container Management Commands

6. Run a Container

docker run <image_name>

Example: docker run hello-world Most Common Variations:

  • docker run -d nginx (detached mode)
  • docker run -it ubuntu bash (interactive terminal)
  • docker run -p 8080:80 nginx (port mapping)

7. Run Container in Background

docker run -d <image_name>

Purpose: Starts container in detached mode, returning container ID

8. Run Interactive Container

docker run -it <image_name> <command>

Example: docker run -it ubuntu /bin/bash Use Case: Access container shell for debugging or development

9. List Running Containers

docker ps

Alternative: docker container ls Shows: Container ID, image, command, creation time, status, ports, names

10. List All Containers

docker ps -a

Purpose: Shows both running and stopped containers

11. Stop a Container

docker stop <container_id_or_name>

Example: docker stop my-nginx-container Graceful Shutdown: Sends SIGTERM signal, waits, then SIGKILL

12. Force Stop Container

docker kill <container_id_or_name>

Use Case: Immediately terminates container (SIGKILL)

13. Start Stopped Container

docker start <container_id_or_name>

Purpose: Restarts a previously stopped container

14. Restart Container

docker restart <container_id_or_name>

Equivalent To: docker stop followed by docker start

15. Remove Container

docker rm <container_id_or_name>

Note: Container must be stopped first, or use -f flag to force

16. Execute Command in Running Container

docker exec -it <container_id_or_name> <command>

Example: docker exec -it my-container bash Common Use: Debugging running containers

17. View Container Logs

docker logs <container_id_or_name>

Useful Options:

  • docker logs -f container_name (follow logs)
  • docker logs --tail 50 container_name (last 50 lines)

18. Inspect Container Details

docker inspect <container_id_or_name>

Returns: JSON formatted detailed information about container configuration

19. View Container Resource Usage

docker stats <container_id_or_name>

Shows: CPU, memory, network, and disk I/O usage in real-time

20. Copy Files Between Container and Host

docker cp <container_id>:<src_path> <dest_path>
docker cp <src_path> <container_id>:<dest_path>

Examples:

  • docker cp mycontainer:/app/config.json ./config.json
  • docker cp ./data.txt mycontainer:/tmp/data.txt

Image Management Commands

21. List Docker Images

docker images

Alternative: docker image ls Shows: Repository, tag, image ID, creation date, size

22. Pull Image from Registry

docker pull <image_name>:<tag>

Examples:

  • docker pull nginx:latest
  • docker pull ubuntu:20.04

23. Build Image from Dockerfile

docker build -t <image_name>:<tag> <path>

Example: docker build -t my-app:v1.0 . Common Options: -f (specify Dockerfile), --no-cache

24. Remove Docker Image

docker rmi <image_id_or_name>

Force Removal: docker rmi -f <image_id>

Need a complete guide on Docker for DevOps?
👉 Check out our pillar post: Docker for DevOps: The Ultimate 2025 Guide to Containerization Success

25. Tag Docker Image

docker tag <source_image> <target_image>:<tag>

Example: docker tag my-app:latest my-registry.com/my-app:v1.0

26. Push Image to Registry

docker push <image_name>:<tag>

Prerequisite: Must be logged in to registry

27. Save Image to Archive

docker save -o <filename>.tar <image_name>

Example: docker save -o nginx-backup.tar nginx:latest

28. Load Image from Archive

docker load -i <filename>.tar

Use Case: Transfer images between systems without registry

29. View Image History

docker history <image_name>

Purpose: Shows layers and commands used to build the image

30. Remove Unused Images

docker image prune

Removes: Dangling images (untagged intermediate images) Force: docker image prune -a (removes all unused images)

Network Commands

31. List Docker Networks

docker network ls

Default Networks: bridge, host, none

32. Create Custom Network

docker network create <network_name>

Example: docker network create my-app-network Driver Options: bridge (default), overlay, macvlan

33. Connect Container to Network

docker network connect <network_name> <container_name>

Use Case: Add running container to additional network

34. Disconnect Container from Network

docker network disconnect <network_name> <container_name>

35. Inspect Network Details

docker network inspect <network_name>

Returns: Network configuration, connected containers, IP addresses

36. Remove Network

docker network rm <network_name>

Note: All containers must be disconnected first

Volume Commands

37. List Docker Volumes

docker volume ls

Purpose: Shows all created volumes for persistent data storage

38. Create Named Volume

docker volume create <volume_name>

Example: docker volume create my-data-volume

39. Inspect Volume Details

docker volume inspect <volume_name>

Shows: Mountpoint, driver, creation date, labels

40. Remove Volume

docker volume rm <volume_name>

Warning: Permanently deletes volume data

41. Remove Unused Volumes

docker volume prune

Caution: Removes all volumes not used by at least one container

Docker Compose Commands

42. Start Services with Docker Compose

docker-compose up

Background Mode: docker-compose up -d Build Images: docker-compose up --build

43. Stop Docker Compose Services

docker-compose down

Remove Volumes: docker-compose down -v Remove Images: docker-compose down --rmi all

44. View Compose Service Logs

docker-compose logs <service_name>

Follow Logs: docker-compose logs -f

45. Scale Services

docker-compose up --scale <service_name>=<number>

Example: docker-compose up --scale web=3

System Management Commands

46. Remove All Stopped Containers

docker container prune

Confirmation Required: Interactive prompt before deletion

47. System-wide Cleanup

docker system prune

Removes: Stopped containers, unused networks, dangling images, build cache Aggressive Cleanup: docker system prune -a --volumes

48. Monitor Docker Events

docker events

Real-time Events: Container starts, stops, image pulls, volume mounts

49. Export Container Filesystem

docker export <container_id> > <filename>.tar

Use Case: Create archive of container’s filesystem

50. Import Filesystem as Image

docker import <filename>.tar <image_name>:<tag>

Creates: New image from exported container filesystem

“Refer to the official Docker CLI Reference for more details.”

Advanced Docker Tips and Best Practices

Resource Management

  • Use --memory and --cpus flags to limit container resources
  • Monitor container performance with docker stats
  • Implement health checks in Dockerfiles

Security Best Practices

  • Run containers as non-root users
  • Use official base images when possible
  • Regularly update images and scan for vulnerabilities
  • Limit container capabilities with --cap-drop

Performance Optimization

  • Use multi-stage builds to reduce image size
  • Leverage Docker layer caching
  • Use .dockerignore to exclude unnecessary files
  • Choose appropriate base images (alpine for smaller size)

Quick Reference Summary

Most Frequently Used Commands

  1. docker run -d -p 8080:80 nginx – Run web server
  2. docker ps – List running containers
  3. docker logs <container> – View logs
  4. docker exec -it <container> bash – Access container shell
  5. docker stop <container> – Stop container
  6. docker rm <container> – Remove container
  7. docker images – List images
  8. docker pull <image> – Download image
  9. docker build -t <name> . – Build image
  10. docker system prune – Clean up system

Common Flag Combinations

  • -d (detached/background mode)
  • -it (interactive terminal)
  • -p (port mapping)
  • -v (volume mounting)
  • -e (environment variables)
  • --name (container naming)
  • --rm (auto-remove after exit)

Troubleshooting Common Docker Issues

Container Won’t Start

  1. Check image availability: docker images
  2. Verify port conflicts: docker ps -a
  3. Examine logs: docker logs <container>
  4. Inspect configuration: docker inspect <container>

Out of Disk Space

  1. Remove unused images: docker image prune -a
  2. Clean up containers: docker container prune
  3. Remove unused volumes: docker volume prune
  4. System cleanup: docker system prune --volumes

Network Connectivity Issues

  1. List networks: docker network ls
  2. Inspect network: docker network inspect <network>
  3. Check container network settings: docker inspect <container>
  4. Test connectivity: docker exec -it <container> ping <target>

Conclusion

Mastering these 50 Docker commands will significantly improve your containerization workflow and productivity. From basic container operations to advanced system management, these commands form the foundation of effective Docker usage.

Remember to regularly practice these commands and refer to the official Docker documentation for the most up-to-date information. As containerization continues to evolve, staying current with Docker best practices and new features will keep your skills sharp and relevant.

Whether you’re deploying microservices, setting up development environments, or managing production workloads, these Docker commands will serve as your reliable toolkit for container orchestration and management.

Pro Tip: Create aliases for frequently used commands in your shell configuration to speed up your Docker workflow. For example:

alias dps='docker ps'
alias dpa='docker ps -a'
alias di='docker images'
alias dsp='docker system prune'

Start with the basic commands and gradually incorporate more advanced techniques as you become comfortable with Docker’s ecosystem. Happy containerizing!

More Docker Resources: Master Containerization and Image Optimization

Similar Posts

5 Comments

Leave a Reply