Docker Week: Day 3 (part 2) – Essential Docker Commands for Every Cloud & DevOps Engineer

I’m a Cloud/DevOps enthusiast currently learning how to build and manage reliable, scalable solutions. I’m excited about exploring modern technologies and best practices to streamline development and deployment processes. My aim is to gain hands-on experience and contribute to creating robust systems that support growth and success in the tech world.
Saturday, 21st September 2024
Why Knowing Docker Commands Matters
Mastering Docker commands is essential for efficiently managing containers, images, volumes, and networks. Whether you're a beginner or an experienced cloud/DevOps engineer, having a good understanding of these commands helps streamline your workflow and manage containerized environments effectively.
Key Docker Commands
Here are some of the most important Docker commands that every cloud or DevOps engineer should know, grouped by category:
1. Docker Basics
docker --version
Check the installed version of Docker on your system.docker --versiondocker help
Get a list of Docker commands or detailed help for a specific command.docker helpdocker info
Displays detailed information about Docker, including the number of running containers, images, and system resources.docker info
2. Container Management
docker run
Run a new container from a specified image.
Example: Run an NGINX container.docker run -d --name my_nginx -p 80:80 nginxdocker ps
List all running containers.docker psdocker ps -a
List all containers, including stopped ones.docker ps -adocker stop [container_id]
Stop a running container by specifying its ID or name.docker stop my_nginxdocker start [container_id]
Start a stopped container by specifying its ID or name.docker start my_nginxdocker rm [container_id]
Remove a stopped container.docker rm my_nginx
3. Image Management
docker images
List all images available locally.docker imagesdocker pull [image_name]
Pull an image from Docker Hub (or another registry).docker pull ubuntudocker rmi [image_name]
Remove a specific image from your local system.docker rmi ubuntudocker build -t [image_name] [path]
Build a Docker image from a Dockerfile.docker build -t my_app .
4. Docker Volumes
docker volume create [volume_name]
Create a new Docker volume.docker volume create my_data_volumedocker volume ls
List all Docker volumes.docker volume lsdocker volume rm [volume_name]
Remove a Docker volume.docker volume rm my_data_volume
5. Docker Networks
docker network ls
List all Docker networks.docker network lsdocker network create [network_name]
Create a custom Docker network.docker network create my_networkdocker network rm [network_name]
Remove a Docker network.docker network rm my_network
6. Logs and Monitoring
docker logs [container_id]
View logs from a running container.docker logs my_nginxdocker stats
Display a live stream of container resource usage.docker statsdocker inspect [container_id]
Get detailed information about a container or image in JSON format.docker inspect my_nginx
7. Executing Commands in Containers
docker exec -it [container_id] [command]
Run a command inside a running container (like accessing a terminal in the container).docker exec -it my_nginx bashdocker attach [container_id]
Attach your terminal to a running container.docker attach my_nginx
8. Cleaning Up
docker system prune
Remove unused Docker objects (containers, networks, images, etc.).docker system prunedocker system df
Show Docker disk usage, providing insights into how much space containers, images, and volumes are consuming.docker system df
Why These Commands Are Essential for Cloud/DevOps Engineers
Mastering these Docker commands is crucial for effective container management in real-world cloud and DevOps environments. They help you streamline operations, troubleshoot issues, and automate tasks, making your workflows faster and more efficient. From setting up applications to managing complex infrastructures, Docker is a core tool for engineers working with containers.
Conclusion
These Docker commands form the foundation of container management and are essential for beginners and intermediate-level cloud/DevOps engineers. The more you use these commands, the more familiar and efficient you will become with Docker's capabilities. In the next post, we’ll explore Docker Networking, a critical component for container communication.
Stay tuned for Day 4 of Docker Week!



