Skip to content

Instantly share code, notes, and snippets.

@hugocosme
Last active July 27, 2020 14:25
Show Gist options
  • Save hugocosme/1566451240a3d797b557e4559a977acd to your computer and use it in GitHub Desktop.
Save hugocosme/1566451240a3d797b557e4559a977acd to your computer and use it in GitHub Desktop.

Revisions

  1. hugocosme revised this gist Jul 27, 2020. No changes.
  2. hugocosme revised this gist Jul 27, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions docker-cleaner.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,10 @@
    #!/bin/bash -e
    #########################################################################################
    ##how to use: ###
    ##download the script "docker-cleaner.sh" adjust the permissions with chmod + x ###
    ##and then execute the script passing the name or ID of the container as a parameter. ###
    ##Eg "./docker-cleaner.sh container-name" ###
    #########################################################################################

    if [[ -z $1 ]]; then
    echo "No container specified"
  3. hugocosme created this gist Jul 27, 2020.
    14 changes: 14 additions & 0 deletions docker-cleaner.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash -e

    if [[ -z $1 ]]; then
    echo "No container specified"
    exit 1
    fi

    if [[ "$(docker ps -aq -f name=^/${1}$ 2> /dev/null)" == "" ]]; then
    echo "Container \"$1\" does not exist, exiting."
    exit 1
    fi

    log=$(docker inspect -f '{{.LogPath}}' $1 2> /dev/null)
    truncate -s 0 $log