Purge or clean all the resources from Docker

Clean up any resources from the Docker

Purge or clear all the resources like networks, images, volumes, and containers that are not linked with any container

# docker system prune

Remove stopped containers and all unused images by using -a

# docker system prune -a

Remove specific images:

--List the images
# docker images -a

--Remove specific images
#docker rmi <imageid>

-- Note: if you want to remove all images 
# docker rmi $(docker images -a -q)

Remove specific containers:

--list all container running or existed
# docker ps -a

--Remove specific container 
# docker rm <containername or containerid>

--Note: IF you want to remove all containers then first stop and remove:
# docker stop $(docker ps -a -q)
# docker rm $(docker ps -a -q)

--Remove only existed status container:
--list them
# docker ps -a -f status=exited
--remove them
# docker rm $(docker ps -a -f status=exited -q)

Remove specific volumes:

--list the volumes
# docker volume ls

--remove the specific volume
# docker volume rm name

--remove all the unused volumes:

# docker volume prune

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.