Skip to content

Instantly share code, notes, and snippets.

@konjoot
Created March 22, 2018 11:43
Show Gist options
  • Save konjoot/7122d3ce3f37bd688798e3bb379665ca to your computer and use it in GitHub Desktop.
Save konjoot/7122d3ce3f37bd688798e3bb379665ca to your computer and use it in GitHub Desktop.
Docker full reset. Removes all docker containers, images, networks and volumes
#!/usr/bin/env bash
RUNNING_CONTAINERS=`docker ps -aq`
if [[ $RUNNING_CONTAINERS ]]; then
docker stop $RUNNING_CONTAINERS
docker rm -f $RUNNING_CONTAINERS
fi
docker network prune -f
DOCKER_TEMP_IMAGES=`docker images --filter dangling=true -qa`
if [[ $DOCKER_TEMP_IMAGES ]]; then
docker rmi -f DOCKER_TEMP_IMAGES
fi
DOCKER_TEMP_VOLUMES=`docker volume ls --filter dangling=true -q`
if [[ $DOCKER_TEMP_VOLUMES ]]; then
docker volume rm -f $DOCKER_TEMP_VOLUMES
fi
DOCKER_ALL_IMAGES=`docker images -qa`
if [[ $DOCKER_ALL_IMAGES ]]; then
docker rmi -f $DOCKER_ALL_IMAGES
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment