Day 20 Essential Docker Cheat Sheet for DevOps Engineers
Basics
Command | Description |
docker --version | Check the installed Docker version. |
docker info | Display system-wide information about Docker. |
Images
Command | Description |
docker pull <image> | Download an image from Docker Hub (or a registry). |
docker images | List all images on the local machine. |
docker rmi <image> | Remove an image from the local machine. |
docker build -t <name>:<tag> <path> | Build an image from a Dockerfile in the specified path. |
docker tag <source> <target> | Tag an image for easier reference. |
Containers
Command | Description |
docker run <options> <image> | Create and start a container from an image. |
docker ps | List running containers. |
docker ps -a | List all containers (running and stopped). |
docker stop <container> | Stop a running container. |
docker start <container> | Start a stopped container. |
docker restart <container> | Restart a running container. |
docker rm <container> | Remove a stopped container. |
docker exec -it <container> <command> | Run a command inside a running container. |
docker logs <container> | View logs for a specific container. |
Volumes
Command | Description |
docker volume create <volume-name> | Create a new volume. |
docker volume ls | List all Docker volumes. |
docker volume inspect <volume-name> | View detailed information about a volume. |
docker volume rm <volume-name> | Remove a specific volume. |
Networks
Command | Description |
docker network ls | List all Docker networks. |
docker network create <network-name> | Create a new network. |
docker network inspect <network-name> | View detailed information about a network. |
docker network rm <network-name> | Remove a specific network. |
Docker Compose
Command | Description |
docker-compose up | Start all services defined in docker-compose.yml . |
docker-compose up -d | Start services in detached mode. |
docker-compose down | Stop and remove all services, networks, and volumes. |
docker-compose ps | List the status of all services. |
docker-compose logs <service> | View logs for a specific service. |
docker-compose build | Build images for services defined in docker-compose.yml . |
docker-compose scale <service>=<num> | Scale a specific service to a defined number of replicas. |
Useful Options
Option | Description |
-d | Run the container in detached mode (in the background). |
-it | Allocate a pseudo-TTY and keep STDIN open (interactive mode). |
--rm | Automatically remove the container when it exits. |
-p <host_port>:<container_port> | Map a port on the host to a port in the container. |
--name <container_name> | Assign a name to the container. |
Common Tasks
Accessing Container Shell
docker exec -it <container> /bin/bash
Removing Unused Images and Containers
docker system prune
Building and Running an Application
Create a Dockerfile in your project directory.
Build the image:
docker build -t <image-name> .
Run the container:
docker run -d -p <host_port>:<container_port> <image-name>
This cheat sheet covers the most commonly used Docker commands for managing containers, images, networks, volumes, and Docker Compose. Let me know if you'd like further details or examples!
We appreciate❤️ you taking the time to read and connect with us! Your engagement means a lot to us, and we look forward to hearing more from you📝
Subscribe to my newsletter
Read articles from Fauzeya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Fauzeya
Fauzeya
Hi there! I'm Fauzeya 👩💻, a passionate DevOps Engineer with a background in Computer Science Engineering🎓. I’m committed to enhancing security🔒, efficiency⚙️, and effectiveness in software development and deployment processes. With extensive knowledge in cloud computing☁️, containerization📦, and automation🤖, I aim to stay updated with the latest tools and methodologies in the DevOps field. Currently, I’m on a journey to deepen my understanding of DevOps I enjoy sharing my learning experiences and insights through my blog, 📝where I cover topics related to DevOps practices, tutorials, and challenges. I believe in continuous growth and learning and am excited to connect with fellow tech enthusiasts and professionals🤝. Let’s embark on this journey together!🚀