Catalog / Docker Cheatsheet
Docker Cheatsheet
A concise reference for Docker commands and concepts, ideal for quick lookups and efficient Docker workflows.
Basic Commands
Image Management
|
Download an image from Docker Hub. |
|
List available images locally. |
|
Remove an image. |
|
Build an image from a Dockerfile in the current directory. |
|
Tag an image. |
|
Push image to Docker Hub or registry. |
Container Management
|
Create and start a container. |
|
List running containers. |
|
List all containers (running and stopped). |
|
Stop a running container. |
|
Start a stopped container. |
|
Restart a container. |
|
Remove a stopped container. |
|
Execute a command inside a container. |
Networking
|
Create a new network. |
|
List available networks. |
|
Connect a container to a network. |
|
List port mappings for a container. |
Dockerfile Instructions
Essential Instructions
|
Specifies the base image for the Dockerfile. |
|
Executes commands during the image build process. |
|
Specifies the default command to run when the container starts. |
|
Declares the port the container listens on. |
|
Sets environment variables. |
|
Copies files/directories from the host to the container. |
|
Similar to COPY, but can also extract archives and fetch URLs. |
|
Sets the working directory for subsequent instructions. |
User and Volume Management
|
Sets the user for subsequent RUN, CMD, and ENTRYPOINT instructions. |
|
Creates a mount point for persistent storage. |
|
Signal to be used to stop the container |
|
Defines a build argument. |
Docker Compose
Compose File Structure
A Key elements include:
|
Common Compose Commands
|
Builds, (re)creates, starts, and attaches to containers defined in a |
|
Runs the containers in detached mode (background). |
|
Stops and removes containers, networks, and volumes defined in the Compose file. |
|
Lists the containers defined in the Compose file. |
|
View the logs of the containers. |
|
Stop services |
|
Start services |
|
Restart services |
Service Configuration
|
Specifies the image to use for the service. |
|
Specifies the path to the Dockerfile to build the image. |
|
Exposes ports from the container to the host. |
|
Mounts volumes to the container. |
|
Sets environment variables for the service. |
|
Defines service dependencies. |
|
Attaches the service to a network. |
Docker Swarm
Swarm Initialization and Management
|
Initializes a new Swarm cluster. Run this on the manager node. |
|
Joins a node to an existing Swarm cluster. Use the token provided by |
|
Leaves the Swarm cluster. Use |
|
Lists the nodes in the Swarm cluster. |
|
Inspect a specific node. |
|
Update node’s role and availability. |
Service Deployment and Scaling
|
Creates a new service in the Swarm cluster. |
|
Lists the services running in the Swarm cluster. |
|
Updates an existing service (e.g., scale, update image). |
|
Scales a service to the specified number of replicas. |
|
Inspect a specific service. |
|
View logs for a specific service. |
|
Removes a service from the Swarm cluster. |
Stack Deployment
|
Deploy a stack based on a compose file. |
|
List deployed stacks. |
|
Remove a deployed stack. |
|
List the tasks in the stack. |