🛠️ Mastering Docker Commands: Your Daily Toolkit
Source: Dev.to

You’ve learned the what, why, and how behind Docker’s architecture and filesystem. Now, let’s get deeply practical with the commands you’ll use every single day to interact with Docker. This post will be your go‑to reference for managing images, containers, and your Docker environment.
We’ve organized the essential commands into categories for easy lookup.
🔍 Docker System & Information Commands
| Command | Description | Example |
|---|---|---|
docker --version | Displays the Docker client version. | docker --version |
docker info | Provides detailed system‑wide information about your Docker installation. | docker info |
docker system df | Shows disk space usage by Docker objects (images, containers, volumes). | docker system df |
docker system prune | Removes unused Docker data (stopped containers, unused networks, dangling images). | docker system prune |
🖼️ Image Management Commands
| Command | Description | Example |
|---|---|---|
docker pull | Downloads an image from a registry (default is Docker Hub) to your local machine. | docker pull ubuntu:latest |
docker images / docker image ls | Lists all images stored locally on your machine. | docker images |
docker search | Searches Docker Hub for images based on a keyword. | docker search nginx |
docker inspect | Displays detailed JSON configuration information about a Docker object. | docker inspect nginx:latest |
docker rmi | Removes one or more images. | docker rmi ubuntu:latest |
🚢 Container Lifecycle Commands
| Command | Description | Example |
|---|---|---|
docker run | Creates and starts a new container from an image. | docker run -it --name my-alpine alpine sh |
docker create | Creates a container but does not start it. | docker create --name my-db postgres |
docker start | Starts one or more stopped containers. | docker start my-db |
docker stop | Stops one or more running containers gracefully. | docker stop my-web-server |
docker restart | Restarts one or more containers. | docker restart my-db |
docker kill | Kills one or more running containers forcefully (sends SIGKILL). | docker kill my-db |
docker ps / docker container ls | Lists running containers. Add -a/--all to list all containers. | docker ps -a |
docker rm | Removes one or more stopped containers. Use -f to force removal of a running container. | docker rm my-alpine |
✨ docker run Options (Flags)
| Option | Meaning | Example Use |
|---|---|---|
-it | Interactive mode (-i interactive, -t TTY). Essential for shell access. | docker run -it alpine sh |
-d | Detached mode. Runs the container in the background. | docker run -d nginx |
-p <hostPort>:<containerPort> | Port mapping. Publishes a container’s port to a host port. | docker run -p 8080:80 nginx |
--name <name> | Assigns a memorable name to the container. | docker run --name my-app … |
--rm | Automatically removes the container when it exits. Great for temporary tasks. | docker run --rm alpine … |
-v <hostPath>:<containerPath> | Volume mount. Mounts a host path or named volume for data persistence. | docker run -v my-data:/data … |
🔬 Container Interaction & Monitoring Commands
| Command | Description | Example |
|---|---|---|
docker exec | Executes a command inside a running container. | docker exec -it my-app sh |
docker logs | Fetches the logs of a container. Use -f to stream logs in real‑time. | docker logs -f my-web-server |
docker top | Displays the running processes within a container. | docker top my-web-server |
docker stats | Shows a live stream of resource usage (CPU, memory, I/O) for running containers. | docker stats |
docker cp | Copies files/folders between a container and the local filesystem. | docker cp my-app:/app/config.ini . |
docker attach | Attaches your terminal to a running container’s streams (use with caution). | docker attach my-alpine |
You now have a robust toolkit and reference guide for managing every aspect of a container’s life.
In our next post, we will finally use this command‑line knowledge to build custom images. We’ll dive into the architecture of a Dockerfile and practice writing efficient instructions!