Created
          December 20, 2023 18:52 
        
      - 
      
- 
        Save nicolas-oliveira/640c628737d8c3d37c381d35dc2122f6 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| ########################################### | |
| # | |
| # Script Shell simples para limpar/remover todos os containers/imagens | |
| loading_spinner() { | |
| duration=1 # Count to 3 seconds | |
| interval=0.1 # Sleep for 0.1 seconds each iteration | |
| start_time=$(date +%s) # Get current timestamp in seconds | |
| while : | |
| do | |
| current_time=$(date +%s) # Get current timestamp in seconds | |
| # Check if 3 seconds have passed | |
| if (( current_time - start_time >= duration )); then | |
| printf "\b \b" # Delete the last character | |
| break | |
| fi | |
| sp="|/-\\" | |
| printf "\b${sp:i++%${#sp}:1}" | |
| sleep $interval | |
| done | |
| } | |
| init() { | |
| printf '\033[0m\n\n' | |
| containers=$(docker ps -aq) | |
| images=$(docker images -q) | |
| volumes=$(docker volume ls -q) | |
| loading_spinner | |
| if [[ -n "$containers" ]]; then | |
| docker stop $containers | |
| docker rm $containers | |
| else | |
| printf "\033[0;32m" | |
| echo "Sem containers para remover" | |
| printf '\033[0m\n' | |
| fi | |
| loading_spinner | |
| if [[ -n "$images" ]]; then | |
| docker rmi $images | |
| else | |
| printf "\033[0;32m" | |
| echo "Sem imagens para remover" | |
| printf '\033[0m\n' | |
| fi | |
| loading_spinner | |
| if [[ -n "$volumes" ]]; then | |
| docker volume rm $volumes | |
| else | |
| printf "\033[0;32m" | |
| echo "Sem volumes para remover" | |
| printf '\033[0m\n' | |
| fi | |
| } | |
| printf "\033[0;31mATENÇÃO\nEste script irá deletar TODOS os dados relacionados ao docker\n" | |
| printf "O script irá:\n- interromper todos os containers em execução (se houver),\n- remover os containers\n- remover imagens\n- remover volumes\n\n" | |
| while true; do | |
| read -p "Você deseja prosseguir? [s\n] " yn | |
| case $yn in | |
| [Ss]* ) init; break;; | |
| [Nn]* ) exit;; | |
| * ) exit;; | |
| esac | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment