Some useful Docker commands

Nishit Ranjan
1 min readApr 11, 2020

1. docker system prune : Will remove all stopped containers, all dangling images and all unused networks
2. docker system prune — volumes : Will remove all unused volumes
3. docker ps -a :- List of all containers
4. docker ps: List of only running containers
5. docker container stop $(docker container ls -aq) : Stop all containers
6. docker container prune : Will remove all stoped containers
7. docker container ls -aq: Will list all Docker containers on your system
8. docker container rm $(docker container ls -aq) : Will remove all containers
9. docker image prune: Can be used to remove dangled and unused docker images
10. docker image prune -a : To remove all images which are not referenced by any existing container, not just the dangling ones,
11. docker volume prune : To remove all unused volumes
12. docker rmi -f $(docker images -a -q) : Delete all Docker image

13. docker inspect -f ‘{{.NetworkSettings.IPAddress}}’ mongo_live : get IP of a running container(here, mongo_live is the name of the container).
14. docker run -it -p 27017:27017 — name mongo_container — link node_container1 -d <container_id_of_mongo> : linking mongo container with node container
15. docker network create example
docker run -d — net example — name container1 <image>
docker run -d — net example — name container2 <image> : linking docker containers

--

--

Nishit Ranjan
0 Followers

I am a software engineer. I specialize in JavaScript, React.js, NodeJS, Docker and Kubernetes.