In the world of DevOps and containerization, Docker has become an essential tool for developers, system administrators, and even beginners. It’s powerful, flexible, and, when used effectively, can drastically speed up your workflows. In this guide, we’ll take you through the top 50 Docker commands you’ll need on a daily basis to manage containers, images, volumes, and more!
What is Docker?
Before we dive into the commands, let’s have a brief overview. Docker is a platform that allows you to automate the deployment of applications inside lightweight, portable containers. Containers encapsulate an application and its dependencies, ensuring it runs the same everywhere.
For a more detailed explanation of configuring Docker, check out this guide on common Dockerfile and YAML configurations.
Why You Need These Commands
Whether you’re a seasoned Docker user or just starting, having a go-to list of Docker CLI commands is crucial for working efficiently. These Docker container commands will help you manage containers, images, networks, and volumes without hassle. Understanding the Docker daily use commands will save you time and make your workflows smoother.
Docker Commands Cheat Sheet
Here’s a list of the most important Docker commands you’ll find yourself using daily:
Basic Docker Commands
docker --version
Check the version of Docker installed on your system.docker info
Get system-wide information about Docker including containers, images, and volumes.docker help
Displays help information about Docker and its commands.docker run [image]
Create and start a container from a Docker image. Example:docker run hello-world
docker ps
List all currently running containers.docker ps -a
List all containers (both running and stopped).docker start [container_name]
Start a stopped container.docker stop [container_name]
Stop a running container.docker restart [container_name]
Restart a running container.docker rm [container_name]
Remove a stopped container.
Docker Image Commands
docker images
List all Docker images on your system.docker pull [image_name]
Download a Docker image from Docker Hub. Example:bashCopy codedocker pull ubuntu
docker rmi [image_name]
Remove a Docker image.docker tag [source_image] [target_image]
Tag an image to create another image.docker build -t [image_name] .
Build a Docker image from a Dockerfile in the current directory.docker history [image_name]
View the history of changes made to a Docker image.
Docker Container Management
docker exec -it [container_name] bash
Access a running container’s shell.docker logs [container_name]
View logs from a running or stopped container.docker inspect [container_name]
View detailed information about a container in JSON format.docker commit [container_name] [new_image_name]
Save the changes in a container as a new image.docker top [container_name]
Display the processes running inside a container.docker diff [container_name]
See changes made to a container’s file system.docker stats
Display a live stream of container resource usage statistics.
Docker Networking Commands
docker network ls
List all Docker networks.docker network inspect [network_name]
View details about a specific Docker network.docker network create [network_name]
Create a new Docker network.docker network connect [network_name] [container_name]
Connect a container to a network.docker network disconnect [network_name] [container_name]
Disconnect a container from a network.
Docker Volume Commands
docker volume ls
List all Docker volumes.docker volume create [volume_name]
Create a new Docker volume.docker volume rm [volume_name]
Remove a Docker volume.docker volume inspect [volume_name]
View detailed information about a volume.docker run -v [volume_name]:[container_path] [image]
Attach a volume to a container.
Docker Image Management
docker save [image_name] > [file_path]
Save a Docker image to a tar archive.docker load < [file_path]
Load a Docker image from a tar archive.docker export [container_name] > [file_path]
Export a container’s file system to a tar archive.docker import [file_path] [new_image_name]
Create a new Docker image from an exported tar archive.
Advanced Docker Commands
docker prune
Remove unused containers, networks, images, and volumes.docker container prune
Remove all stopped containers.docker image prune
Remove unused Docker images.docker system prune
Remove all unused Docker data.
Additional Useful Commands
docker attach [container_name]
Attach your terminal to a running container.docker rename [old_name] [new_name]
Rename a container.docker cp [container_name]:[source_path] [destination_path]
Copy files or directories between a container and the local filesystem.docker pause [container_name]
Pause all processes within a container.docker unpause [container_name]
Unpause a paused container.docker update [container_name] [options]
Update configuration of a container.docker wait [container_name]
Block until a container stops and then print its exit code.docker events
Get real-time events from the Docker daemon.docker search [term]
Search for Docker images on Docker Hub.
Conclusion
Mastering these Docker commands will improve your daily container management. From basic container operations to advanced image and network configurations, these commands help optimize Docker’s functionality.
If you’re just starting with Docker, we recommend reading this guide on how to install Docker on Ubuntu or exploring our Beginner’s Guide to Kubernetes to understand how Docker integrates with other tools.
External Reference
For more in-depth Docker documentation, visit the official Docker documentation.
- Top 10 Cloud IAM Providers for Small Businesses in 2024: Secure Your Digital Assets - 30 September 2024
- Active Directory Security in Hybrid Environments: Challenges and Solutions for 2024 - 29 September 2024
- How to Secure Active Directory: Best Practices and Pro Tips - 28 September 2024