Docker commands cheat sheet

Rokin Maharjan
Sep 2, 2018 · 1 min read

Here are some of the most used docker commands.

1. Run a container

docker run image-name

2. Run a container in detached mode

docker run -d image-name

3. Stop all running containers

docker kill $(docker ps -q)

4. Delete all stopped containers

docker rm $(docker ps -a -q)

5. Delete all images

docker rmi $(docker images -q)

6. Force delete all images

docker rmi -f $(docker images -q)

7. Port mapping

docker run -p host_port:docker_port image-name

8. Volume mapping

docker run -v host_volume:docker_volume image-name

9. Run commands inside container

docker exec container-id command

10. Go inside container

docker exec -it container-id bash

11. Inspect a container (eg. to find internal IP of container, image it is using etc)

docker inspect container-id

This blog is based on my github gist https://gist.github.com/rokinmaharjan/df67d114e84b4ad22b191c85f78c658e .

Thanks for reading. Hope this helps! :)

Rokin Maharjan

Written by

Software Engineer at Fusemachines

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade