Handy Docker commands

1. Remove all your containers and images, using following commands:
docker kill $(docker ps -q) : Kill all running containers
docker rm $(docker ps -a -q) : Delete all stopped containers after previous command
docker rmi $(docker images -q) : Delete all images

You may find following error:
“Error response from daemon: conflict: unable to delete image_hash (must be forced) – image is referenced in multiple repositories”
docker rmi -f image_hash : To force removing an image.

2. To list running containers
docker ps
-a / -all : all containers
—-quiet /-q : list just containers’ ids

3. To pull images from Docker Hub registry
docker pull

4. To build Docker images from a Dockerfile and a “context”
docker build

A build’s context is the set of files located in the specified PATH or URL. Use the -t flag to label the image, for example docker build -t my_container . with the . at the end signalling to build using the currently directory.

5. To run a docker container based on an image
docker run

6. To list the volumes
docker volume ls

7. To remove one or more containers. docker rm my_container
docker rm my_container

8. To remove one or more images. docker rm my_image
docker rmi my_image

9. To stop my_container
docker stop my_container

10. To stop all running containers
docker stop $(docker ps -a -q)

About: tientham

Software Engineer, SW Integrator & Mobile , Full Stack Developer

Leave a Reply

Your email address will not be published. Required fields are marked *