DEV Community

Shivam Singhal
Shivam Singhal

Posted on • Originally published at itsopensource.com

3 3

How to remove all images and containers in Docker

Recently I started using Docker in my internship and sometimes you just mess up your docker images and containers, so you wanted to start from clean but first you need to remove all images and containers of Docker locally.

# Delete all Docker containers
docker rm -f $(docker ps -a -q)

# Delete all Docker images
docker rmi -f $(docker images -q)

Also there is a new docker command, that will delete all unused images and volumes.

docker system prune --all --force

You can read more about this command here

Follow me on GitHub and Twitter

Cheers!


Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
aminnairi profile image
Amin • Edited

Hi Shivam, thanks for sharing this trick with us.

You can also go deeper and prune all networks with this command (if you don't use docker system prune):

$ docker network prune

The same thing goes for the volumes:

$ docker volume prune
Collapse
 
geekypandey profile image
Anurag Pandey

Nice! There is also

docker container prune

for the same.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay