Created
April 4, 2020 16:11
-
-
Save vincenzopalazzo/2de7fae9350473d25902876e1e5db04e to your computer and use it in GitHub Desktop.
UNIX script to clean docker after traning or test IMPORTANT this script clean all container and images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#linux Script to clean docker containers and images | |
$RUN_WITH_SUDO=1 #Insert 0if you have docker with user permission | |
if [! RUN_WITH_SUDO] | |
then | |
for NAME in $(sudo docker ps -a) | |
do | |
sudo docker stop $NAME && sudo docker rm $NAME | |
done | |
for IMAGE_VERSION in $(sudo docker images) | |
do | |
sudo docker rmi --force $IMAGE_VERSION | |
done | |
else | |
for NAME in $(docker ps -a) | |
do | |
docker stop $NAME && docker rm $NAME | |
done | |
for IMAGE_VERSION in $(docker images) | |
do | |
docker rmi --force $IMAGE_VERSION | |
done | |
fi | |
echo 'Script end' | |
sudo docker ps -a | |
sudo docker images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The commands return this response patter
sudo docker ps -a:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
sudo docker images:
REPOSITORY TAG IMAGE ID CREATED SIZE