dotfiles/legacy/bin/docker_cleanup

27 lines
608 B
Plaintext
Raw Permalink Normal View History

2020-06-03 14:31:58 +00:00
#!/bin/sh
# Stop all containers
if [ "$(docker ps -a -q)" ]; then
echo "Stopping docker containers..."
2022-03-18 12:34:43 +00:00
docker stop "$(docker ps -a -q)"
2020-06-03 14:31:58 +00:00
else
echo "No running docker containers."
fi
# Remove all stopped containers
if [ "$(docker ps -a -q)" ]; then
echo "Removing docker containers..."
2022-03-18 12:34:43 +00:00
docker rm "$(docker ps -a -q)"
2020-06-03 14:31:58 +00:00
else
echo "No stopped docker containers."
fi
# Remove all untagged images
if [[ $(docker images | grep "^<none>") ]]; then
2022-03-18 12:34:43 +00:00
docker rmi "$(docker images | grep "^<none>" | awk '{print $3}')"
2020-06-03 14:31:58 +00:00
else
echo "No untagged docker images."
fi
echo "Cleaned up docker."