#!/usr/bin/env bash
set -e
STOP=0
CONTAINERS=0
IMAGES=0
while getopts ":sci" opt; do
case $opt in
s)
STOP=1
;;
c)
CONTAINERS=1
;;
i)
IMAGES=1
;;
\?)
echo "Invalid option -$OPTARG" >&2
;;
esac
done
# Stop all running containers
if [ $STOP -eq 1 ]; then
docker kill $(docker ps -q)
fi
# Delete all containers
if [ $CONTAINERS -eq 1 ]; then
docker rm $(docker ps -a -q)
fi
# Delete all images
if [ $IMAGES -eq 1 ]; then
docker rmi $(docker images -q)
fi