I recently started using Docker and never realized that I should use docker-compose down
instead of ctrl-c
or docker-compose stop
to get r
To delete all Docker local Docker images follow 2 steps ::
step 1 : docker images ( list all docker images with ids )
example :
REPOSITORY TAG IMAGE ID CREATED SIZE
pradip564/my latest 31e522c6cfe4 3 months ago 915MB
step 2 : docker image rm 31e522c6cfe4 ( IMAGE ID)
OUTPUT : image deleted
Another way with xargs
docker image ls -q | xargs -I {} docker image rm -f {}
sudo docker rm image <image_id>
/ docker rm image <image_id>
Here is the command I used and put it in a batch file to remove everything:
echo "Removing containers :" && if [ -n "$(docker container ls -aq)" ]; then docker container stop $(docker container ls -aq); docker container rm $(docker container ls -aq); fi; echo "Removing images :" && if [ -n "$(docker images -aq)" ]; then docker rmi -f $(docker images -aq); fi; echo "Removing volumes :" && if [ -n "$(docker volume ls -q)" ]; then docker volume rm $(docker volume ls -q); fi; echo "Removing networks :" && if [ -n "$(docker network ls | awk '{print $1" "$2}' | grep -v 'ID|bridge|host|none' | awk '{print $1}')" ]; then docker network rm $(docker network ls | awk '{print $1" "$2}' | grep -v 'ID|bridge|host|none' | awk '{print $1}'); fi;