Stop all running containers:
docker stop $(docker ps -q)
Remove all containers:
docker rm $(docker ps -a -q)
Once all containers are stopped and removed, you can delete all images:
docker rmi $(docker images -q)
You can combine these steps into a single sequence of commands:
docker stop $(docker ps -q) && docker rm $(docker ps -a -q) && docker rmi $(docker images -q)
docker ps -q
: Lists the IDs of all running containers.docker ps -a -q
: Lists the IDs of all containers (both running and stopped).docker images -q
: Lists the IDs of all images.
This process ensures that you stop and remove all containers before deleting all images. This prevents any conflicts or errors due to containers still using the images.