Newer
Older

jurgenhaas
committed
#!/bin/bash
function removecontainer() {
docker container ls --all -q -f name=^${PROJECT}_ >/tmp/reset.lst

jurgenhaas
committed
IDS=$(cat /tmp/reset.lst)
if [[ ! -n ${IDS} ]]; then
echo "No containers to be removed."
return
fi
echo "Deleting containers ..."
for CONTAINERID in $(cat /tmp/reset.lst); do

jurgenhaas
committed
docker rm -f $CONTAINERID
done
rm /tmp/reset.lst
}
function removenetwork() {
ID=$(docker network ls -q -f name=${PROJECT}_default)

jurgenhaas
committed
if [[ ! -n ${ID} ]]; then
echo "No network to be removed."
return
fi
echo "Deleting network ..."
docker network rm ${PROJECT}_default

jurgenhaas
committed
}
function rebuildtraefik() {
cd ${HOME}/.traefik || return
if [[ -f "docker-compose.yml" ]]; then
docker compose --project-name traefik up -d --remove-orphans
fi
if [[ "$NETWORKS" == "" ]]; then
return
fi
docker network rm ${NETWORKS}
}

jurgenhaas
committed
if [[ -n $1 ]]; then
NETWORKS=""
while [[ -n $1 ]]; do
PROJECT=$1
read -p "Are you sure you want to remove the project ${PROJECT} with all containers and network? Type YES to confirm: " CONFIRM
if [[ "$CONFIRM" == YES ]]; then
removecontainer
removenetwork
fi
shift
done
rebuildtraefik

jurgenhaas
committed
else
echo "Please provide the project name you want to delete."
exit
fi