
🔧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:
dockerrm <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):
dockerexec-it <container_id> /bin/bash
- Copy Files from Container to Host:
dockercp <container_id>:<path_inside_container> <host_path>
🏗Docker Networks
- List Networks:
docker networkls
- 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 volumels
- 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: Usedocker system prune
to remove unused containers, networks, and images.
Feel free to save or bookmark this cheat sheet for quick reference!
Docker #CheatSheet #Containers #DevOps
Top comments(26)

- LocationConstanta, Romania
- WorkFull-Stack Web Developer
- Joined
You can also make a helper script:
New file at the root folder calleddc
without extension.
Content example. Modify for your needs.
#!/bin/bashtrap"exit" 0DC="docker compose"# add `-f docker/compose.yml` if it's in another folderif[$#-eq 0];then$DC ps-aelif[$1=="up"];then$DC up-delif[$1=="nr"];then if[$#-gt 1];then$DCexecnode su node-c"${*:2}"else$DCexecnode su nodefielif[$1=="npm"];then$DCexecnode su node-c"npm${*:2}"elif[$1=="install"];then$DCexecnode su node-c'npm install'elif[$1=="recreate"];then$DC up-d--force-recreate${*:2}elif[$1=="build"];then$DC up-d--force-recreate--build${*:2}else$DC$*fi
Give execute permission withchmod +x ./dc
And now you can run:
./dc
to show all containers with status./dc up
to start in detached mode./dc install
to run npm install in the node container as user node./dc npm install package-name-here
to run any npm command inside node container. Works with./dc npm run start
too./dc nr
interactive exec inside node container./dc nr node index.js
run any command inside node container./dc recreate
applies any modifications to docker-compose.yml./dc recreate node
applies modifications to compose, only for node container./dc build
if 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.

- LocationPakistan
- EducationBSIT
- PronounsHe/Him
- WorkStudent
- Joined
Adding one more
docker system prune
This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- unused build cache

- LocationBerlin, Germany
- EducationM.Sc. Computer Engineering
- Pronounshe/him/his
- WorkFreelancing Software Engineer
- Joined
This is awesome! Instantly added togithub.com/devmount/CheatSheets
Thank you!

Thank you@keshav___dev

- LocationBrazil
- PronounsHe / Him
- Joined
Hi keshav Sandhu,
Top, very nice and helpful !
Thanks for sharing.

- EducationRebase Academy
- Pronounshe/him
- WorkFull stack web developer
- Joined
Thanks man

This is incredible.

- Email
- Locationlocalghost:1337
- EducationBachelor of Computer Science
- Pronounshe/him
- WorkSenior Software Engineer @ iris.ai
- Joined
Excellent article, thank you! 💯
Something that made me smile, you can tell that the banner image was created using AI :D

- Joined
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
For further actions, you may consider blocking this person and/orreporting abuse