#!/bin/bash

# This script destroys all Docker containers, images, and networks.
# SOURCE: https://gist.github.com/JeffBelback/5687bb02f3618965ca8f

docker/nukec

echo '-----------------------'
echo 'docker network prune -f'
docker network prune -f

echo '--------------------------------------'
echo 'Killing and removing all Docker images'

for i in $(docker images -a -q)
do
  echo "Evaluating $(docker image inspect --format='{{ .RepoTags }}' $i)"
  if [[ $(docker image inspect --format='{{ .RepoTags }}' $i) =~ "openfoodnetwork" ]]
  then
    echo "Deleting $i"
    docker kill $i; wait;
    docker rmi -f $i; wait;
  else
    echo 'Ignoring container not related to OFN'
  fi
done;

echo '------------'
echo 'docker ps -a'
docker ps -a

echo '----------------'
echo 'docker images -a'
docker images -a

wait
