Docker Cheatsheet
Docker
Containers
DevOps
Orchestration
Complete reference for Docker commands, from basic container operations to advanced orchestration with Docker Compose, services, stacks, and Docker Machine.
Quick Reference
🐳 Basic Commands
Essential Docker container and image operations
🔧 Docker Compose
Multi-container application management
⚙️ Services & Stacks
Production deployment and scaling
🖥️ Docker Machine
Virtual machine provisioning and management
Basic Docker Commands
Getting Started
Creates Docker-related starter files
Create image using this directory's Dockerfile
Run "friendlyname" mapping port 4000 to 80
Same thing, but in detached mode
Container Management
Enter a running container
See a list of all running containers
See a list of all containers, even the ones not running
Gracefully stop the specified container
Force shutdown of the specified container
Remove the specified container from this machine
Remove force specified container from this machine
Remove all containers from this machine
Image Management
Show all images on this machine
Remove the specified image from this machine
Remove all images from this machine
Tag <image>
for upload to registry
Upload tagged image to registry
Run image from a registry
Logging and Registry
Live tail a container's logs
Log in this CLI session using your Docker credentials
System Cleanup
Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes
Remove all unused containers, networks, images not just dangling ones
Remove all unused local volumes
Remove all unused networks
Docker Compose
Docker Compose is perfect for defining and running multi-container Docker applications using a YAML file.
Basic Operations
Create and start containers
Create and start containers in detached mode
Stop and remove containers, networks, images, and volumes
Restart all service
Development & Debugging
View output from containers
Validate and view the Compose file
Display the running processes
Start web service and runs bash as its command, remove old container
Image & Service Management
Pull all image service
Build all image service
Scale special service(s)
Docker Services
Docker services are used in Docker Swarm mode for managing containerized applications across multiple nodes.
Service Management
Create new service
List Services
List the tasks of Services
Display detailed information Service(s)
Scaling & Updates
Scale special service(s)
Update Service options
Docker Stack
Docker Stack is used to deploy and manage a complete application stack in Docker Swarm mode.
Stack Operations
List all running applications on this Docker host
Run the specified Compose file
List the services associated with an app
List the running containers associated with an app
Tear down an application
Docker Machine
Docker Machine is primarily used for provisioning Docker hosts on various platforms and cloud providers.
Machine Creation
Create a VM (Mac, Win7, Linux)
Win10
Machine Management
Start a VM that is currently not running
Stop all running VMs
Delete all VMs and their disk images
Machine Information & Access
View basic information about your node
Open an SSH session with the VM; type "exit" to end
Copy file to node's home dir
Swarm Operations via Machine
List the nodes in your swarm
Inspect a node
View join token
Make the worker leave the swarm
Make master leave, kill swarm
Deploy an app
Best Practices
Follow these Docker best practices for better performance and security.
- Use .dockerignore to exclude unnecessary files from the build context
- Multi-stage builds to keep final images small and secure
- Non-root users in containers for better security
- Health checks to monitor container health
- Resource limits to prevent containers from consuming too many resources
- Environment-specific configs using environment variables
- Regular cleanup of unused images, containers, and volumes
Learn More
Explore comprehensive Docker documentation
Written by
Deepak Jangra
Created At
Wed Jan 15 2025
Updated At
Fri Jun 13 2025