The Ultimate Docker Cheat Sheet. docker_cheatsheet. A cheatsheet is a concise summary of important information that is meant to be used as a quick reference.
Docker has become an essential tool for developers, especially when managing applications across different environments. Here’s a quick cheat-sheet to get started with Docker, explained in first-person and active voice. I’ll break down what each command does so that you’re always in control. Let’s dive right in!

Basic Docker Commands
Start Docker
- Linux:
systemctl start docker
- macOS:
open -a Docker
- Why: This command starts the Docker service on your machine, so you can run containers and images.
Check Docker Versiondocker --version
- Why: Displays the current Docker version installed on your machine. Handy for compatibility checks.
Working with Containers
List Running Containersdocker ps
- Why: Shows a list of all containers that are currently running on your system.
List All Containers (Running + Stopped)docker ps -a
- Why: Lists both active and inactive (stopped) containers.
Run a Containerdocker run <image_name>
- Why: Downloads the image (if not available locally) and starts the container interactively.
Run in Detached Modedocker run -d <image_name>
- Why: Starts a container in the background (detached), freeing up your terminal for other commands.
Run with Port Mappingdocker run -p <host_port>:<container_port> <image_name>
- Why: Maps the container’s port to your machine’s port so that you can access it through a browser or another client.
Stop a Running Containerdocker stop <container_id>
- Why: Gracefully stops a running container.
Start a Stopped Containerdocker start <container_id>
- Why: Restarts a previously stopped container without running a new one.
Remove a Stopped Containerdocker rm <container_id>
- Why: Deletes the stopped container to free up space.
Managing Docker Images
List Docker Imagesdocker images
- Why: Displays all downloaded images on your system.
Pull an Image from Docker Hubdocker pull <image_name>
- Why: Downloads an image from Docker Hub for local use.
Build an Image from a Dockerfiledocker build -t <image_name> .
- Why: Creates a Docker image from a Dockerfile, allowing you to package your application with all dependencies.
Tag an Imagedocker tag <image_id> <new_image_name>:<tag>
- Why: Tags an image with a specific name and version (tag), useful for version control.
Remove an Imagedocker rmi <image_id>
- Why: Deletes a Docker image to free up disk space.
Container Management
View Logs of a Containerdocker logs <container_id>
- Why: Displays the logs of a running container to troubleshoot issues.
Access a Running Container (Interactive Shell)docker exec -it <container_id> /bin/bash
- Why: Opens an interactive shell inside a running container, allowing you to interact directly.
Copy Files from Container to Hostdocker cp <container_id>:<path_inside_container> <host_path>
- Why: Copies files from a container to your host machine.
Networking with Docker
List Networksdocker network ls
- Why: Lists all available Docker networks.
Create a Networkdocker network create <network_name>
- Why: Creates a custom network for containers to connect to.
Connect a Running Container to a Networkdocker network connect <network_name> <container_id>
- Why: Connects an existing running container to a specified network.
Docker Compose
Start Services in Detached Modedocker-compose up -d
- Why: Starts services defined in your
docker-compose.yml
file in the background.
Stop Servicesdocker-compose down
- Why: Stops and removes all services and containers created by Docker Compose.
Build and Start Containersdocker-compose up --build
- Why: Builds the images and starts the containers defined in the
docker-compose.yml
.
Inspecting and Monitoring
Inspect Container Detailsdocker inspect <container_id>
- Why: Displays detailed information about a container’s configuration and status.
Display Resource Usage (CPU, Memory)docker stats
- Why: Shows real-time CPU, memory, and network usage of running containers.
Working with Volumes
List Volumesdocker volume ls
- Why: Lists all Docker volumes available on your system.
Create a Volumedocker volume create <volume_name>
- Why: Creates a new volume to store persistent data.
Mount a Volumedocker run -v <volume_name>:<path_inside_container> <image_name>
- Why: Mounts a volume to your container, ensuring data persists even after the container is stopped or removed.
That’s it! You now have a solid reference to start managing your Docker environment like a pro. Remember, practice makes perfect, so don’t hesitate to explore and experiment with these commands. Happy Dockering!
A Note From the Author
Thank you so much for taking the time to read the story. If you found my article helpful and interesting, please share your thoughts in the comment section, and don’t forget to share and clap
Let’s Get in Touch!
- YouTube: mrcoder701
- Instagram: mr_coder_701
- LinkedIn: Gajanan Rajput
- Website: mrcoder701.com
- GitHub: @gajanan0707
- Medium: Gajanan Rajput
wonderful submit, very informative. I ponder why the opposite specialists of this sector do not realize this. You must proceed your writing. I’m sure, you’ve a great readers’ base already!
I almost never comment, however i did some searching and
wound up hedre Docker Cheat-sheet for beginners – 🌟Code
with MrCoder7️⃣0️⃣1️⃣
. And I actuallyy do have some questions foor you if you do not mind.
Could it be only me or does it appear like a few of thnese comments
appear as if they are left by brain dead people?
😛 And, if you are writing on other online social sites, I would like to keep up with anything fresh you have to post.
Would yoou make a liszt of the coomplete urls of your community pages like
your linkedin profile, Facebook page or twitter feed? http://Boyarka-Inform.com/