github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/Decentralized-Energy-Composer-master/fabric-dev-servers/teardownAllDocker.sh (about)

     1  #!/bin/bash
     2  
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  # 
     7  # http://www.apache.org/licenses/LICENSE-2.0
     8  # 
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # BASH function that kill and remove the running containers
    16  function stop()
    17  {
    18  
    19  P1=$(docker ps -q)
    20  if [ "${P1}" != "" ]; then
    21    echo "Killing all running containers"  &2> /dev/null
    22    docker kill ${P1}
    23  fi
    24  
    25  P2=$(docker ps -aq)
    26  if [ "${P2}" != "" ]; then
    27    echo "Removing all containers"  &2> /dev/null
    28    docker rm ${P2} -f
    29  fi
    30  }
    31  
    32  # Function to remove the images as well
    33  function remove()
    34  {
    35  P=$(docker images -aq)
    36  if [ "${P}" != "" ]; then
    37    echo "Removing images"  &2> /dev/null
    38    docker rmi ${P} -f
    39  fi
    40  }
    41  
    42  echo "For all Docker containers or images (not just Hyperledger Fabric and Composer)"
    43  echo "1 - Kill and remove only the containers"
    44  echo "2 - Kill and remove the containers and remove all the downloaded images"
    45  echo "3 - Quit and not do anything"
    46  echo
    47  PS3="Please select which option > "
    48  options=("Kill & Remove" "Remove Images" "Quit")
    49  select yn in "${options[@]}"; do
    50      case $yn in
    51          "Kill & Remove" ) stop;  break;;
    52          "Remove Images" ) stop;  remove; break;;
    53          "Quit" ) exit;;
    54      esac
    55  done