Docker Command

  1. Stop all running containers: This is important because you can't remove an image of a container that is still running.

    bashCopy codesudo docker stop $(sudo docker ps -aq)
  2. Remove all containers: Once all containers are stopped, you can remove them.

    bashCopy codesudo docker rm $(sudo docker ps -aq)
  3. Remove all Docker images: This will remove all images, including unused and dangling images.

    bashCopy codesudo docker rmi $(sudo docker images -q)
  4. Remove all volumes: Volumes are used for persisting data of Docker containers. To remove them, use:

    bashCopy codesudo docker volume rm $(sudo docker volume ls -q)
  5. Remove all dangling volumes: These are volumes that are no longer used by any containers.

    bashCopy codesudo docker volume prune
  6. (Optional) Remove all networks: If you also want to remove all networks, you can use:

    bashCopy codesudo docker network prune

Last updated