"The Ultimate Docker Cheat Sheet for DevOps: Essential Commands & Tips to Master Containers! ๐ณ๐๐"
Day 20: Docker for DevOps Engineers - Creating Your Ultimate Docker Cheat Sheet ๐๐
Congratulations! ๐ You've completed the hands-on sessions with Docker, mastering everything from building images and managing containers to configuring networks and volumes. Now, it's time to put it all together into one valuable resourceโa Docker Cheat Sheet! This will be your go-to guide, packed with essential commands and explanations to make Docker easier for you and help others in the DevOps community. ๐
Letโs dive into how you can create a cheat sheet thatโs unique, informative, and accessible to anyone, even if theyโre new to Docker. ๐ก
Why Create a Docker Cheat Sheet? ๐ค
Having a Docker cheat sheet is like having a quick reference guide for everything youโve learned:
Efficiency: Find the exact command you need without searching online or reading through long documents.
Learning Tool: Reinforces your knowledge and helps you retain what youโve learned.
Community Support: Sharing this cheat sheet on LinkedIn helps others who are learning Docker, adding value to the DevOps community. ๐
๐ณ Docker Cheat Sheet
1. Docker Basics ๐น
| Command | Description | | --- | --- | |
docker --version
| Show Docker version installed | |docker info
| Display Docker system information | |docker help
| List available Docker commands | |docker run <image>
| Run a new container | |docker run -d <image>
| Run container in detached mode | |docker run -it <image> bash
| Start a container interactively | |docker ps
| List running containers | |docker ps -a
| List all containers (including stopped) | |docker stop <container>
| Stop a running container | |docker start <container>
| Start a stopped container | |docker restart <container>
| Restart a container | |docker rm <container>
| Remove a stopped container | |docker rmi <image>
| Remove an image | |docker system prune
| Remove unused data (containers, images, networks) | |docker top <container>
| Show processes running inside a container | |docker stats
| Display a live stream of container stats |2. Working with Docker Images ๐ผ๏ธ
| Command | Description | | --- | --- | |
docker pull <image>
| Download an image from Docker Hub | |docker images
| List all downloaded images | |docker build -t <image_name> .
| Build an image from a Dockerfile | |docker tag <source_image> <new_image:tag>
| Add a tag to an image | |docker push <image>
| Push an image to Docker Hub | |docker history <image>
| View history of an image | |docker inspect <image>
| Show details of an image | |docker image prune
| Remove unused images |3. Container Management โ๏ธ
| Command | Description | | --- | --- | |
docker exec -it <container> <command>
| Execute a command inside a running container | |docker logs <container>
| View logs from a container | |docker cp <container>:/path/to/file .
| Copy file from container to local system | |docker commit <container> <new_image>
| Create a new image from container changes | |docker rename <old_name> <new_name>
| Rename a container | |docker diff <container>
| Show changes to files/folders in containerโs filesystem |4. Docker Volumes ๐
| Command | Description | | --- | --- | |
docker volume create <volume_name>
| Create a new volume | |docker volume ls
| List all volumes | |docker volume rm <volume_name>
| Remove a volume | |docker run -v <volume_name>:/path <image>
| Mount volume to a container | |docker volume inspect <volume_name>
| View details of a volume | |docker volume prune
| Remove all unused volumes |5. Docker Networks ๐
| Command | Description | | --- | --- | |
docker network create <network_name>
| Create a new network | |docker network ls
| List all networks | |docker network rm <network_name>
| Remove a network | |docker network inspect <network_name>
| View details of a network | |docker run --network <network_name> <image>
| Connect a container to a specific network | |docker network connect <network_name> <container>
| Connect an existing container to a network | |docker network disconnect <network_name> <container>
| Disconnect a container from a network |6. Docker Compose ๐
| Command | Description | | --- | --- | |
docker-compose up
| Start all services defined indocker-compose.yml
| |docker-compose up -d
| Start services in detached mode | |docker-compose down
| Stop and remove containers, networks, volumes | |docker-compose ps
| List containers managed by Docker Compose | |docker-compose logs
| View logs for all services | |docker-compose logs <service>
| View logs for a specific service | |docker-compose build
| Build images defined indocker-compose.yml
| |docker-compose stop
| Stop all services | |docker-compose start
| Start all stopped services | |docker-compose restart
| Restart all services | |docker-compose exec <service> <command>
| Run a command in a service container | |docker-compose config
| Validate and viewdocker-compose.yml
configuration |7. Useful Docker Utilities ๐ ๏ธ
| Command | Description | | --- | --- | |
docker save -o <file>.tar <image>
| Save an image to a tar archive | |docker load -i <file>.tar
| Load an image from a tar archive | |docker export -o <file>.tar <container>
| Export containerโs filesystem to a tar file | |docker import <file>.tar
| Import tar file as an image | |docker events
| Real-time events from the Docker server | |docker container stats
| Monitor resource usage stats for containers |How to Use This Cheat Sheet ๐
Bookmark It: Save this cheat sheet for quick reference whenever youโre working with Docker.
Share with Others: Share this cheat sheet with anyone whoโs learning Docker or working in DevOps.
Customize for Your Needs: Feel free to add more commands or remove those you donโt use often. Make it your personal go-to guide!
Subscribe to my newsletter
Read articles from Saksham Kamble directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by