🔧 Common Docker Commands
- Start Docker:
systemctl start docker # Linux open -a Docker # macOS - Check Docker Version:
docker --version 📦 Working with Containers
- List Running Containers:
docker ps - List All Containers (Running + Stopped):
docker ps -a - Run a Container (starts and attaches):
docker run <image_name> - Run in Detached Mode:
docker run -d <image_name> - Run with Port Mapping:
docker run -p <host_port>:<container_port> <image_name> - Stop a Running Container:
docker stop <container_id> - Start a Stopped Container:
docker start <container_id> - Remove a Stopped Container:
docker rm <container_id> 📜 Images
- List Docker Images:
docker images - Pull an Image from Docker Hub:
docker pull <image_name> - Build an Image from Dockerfile:
docker build -t <image_name> . - Tag an Image:
docker tag <image_id> <new_image_name>:<tag> - Remove an Image:
docker rmi <image_id> 🔄 Container Management
- View Logs of a Container:
docker logs <container_id> - Access a Running Container (Interactive Shell):
docker exec -it <container_id> /bin/bash - Copy Files from Container to Host:
docker cp <container_id>:<path_inside_container> <host_path> 🏗 Docker Networks
- List Networks:
docker network ls - Create a Network:
docker network create <network_name> - Connect a Running Container to a Network:
docker network connect <network_name> <container_id> 🐳 Docker Compose
- Start Services in Detached Mode:
docker-compose up -d - Stop Services:
docker-compose down - Build and Start Containers:
docker-compose up --build 📊 Inspecting and Monitoring
- Inspect Container Details:
docker inspect <container_id> - Display Resource Usage (CPU, Memory):
docker stats 🛠 Volumes
- List Volumes:
docker volume ls - Create a Volume:
docker volume create <volume_name> - Mount a Volume (during
docker run):
docker run -v <volume_name>:<path_inside_container> <image_name> 💡 Pro Tip: Use docker system prune to remove unused containers, networks, and images.
Feel free to save or bookmark this cheat sheet for quick reference!
Top comments (26)
You can also make a helper script:
New file at the root folder called
dcwithout extension.Content example. Modify for your needs.
Give execute permission with
chmod +x ./dcAnd now you can run:
./dcto show all containers with status./dc upto start in detached mode./dc installto run npm install in the node container as user node./dc npm install package-name-hereto run any npm command inside node container. Works with./dc npm run starttoo./dc nrinteractive exec inside node container./dc nr node index.jsrun any command inside node container./dc recreateapplies any modifications to docker-compose.yml./dc recreate nodeapplies modifications to compose, only for node container./dc buildif you have a custom dockerfile, does run dc up with a fresh build../dc logs -n 10 -f node- any other docker-compose command works as expected.Adding one more
docker system pruneThis will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- unused build cache
This is awesome! Instantly added to github.com/devmount/CheatSheets
Thank you!
@devmount Your Github profile is super cool, bro. Much to learn
Thank you so much 🤗
Thanks!!
Thank you @keshav___dev
The most used commands in docker.
Thank for Writing.
Hi keshav Sandhu,
Top, very nice and helpful !
Thanks for sharing.
Thanks man
This is incredible.
Excellent article, thank you! 💯
Something that made me smile, you can tell that the banner image was created using AI :D
If service is there, why not use it 😉
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more