#!/bin/bash

# This script destroys all Docker containers but leaves the Docker images alone.

echo '------------------------------------------'
echo 'Killing and removing all Docker containers'
 
for i in $(docker ps -a -q)
do
  echo "Evaluating $(docker inspect --format='{{ .Name }}' $i)"
  if [[ $(docker inspect --format='{{ .Name }}' $i) =~ "openfoodnetwork" ]]
  then
    echo "Deleting OFN container: $i"
    docker kill $i; wait;
    docker rm -f $i; wait;
  else
    echo 'Ignoring container not related to OFN'
  fi
done;

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