Last active
January 19, 2019 18:54
-
-
Save soywiz/819557135345a17143d2dabb7e875eb6 to your computer and use it in GitHub Desktop.
Small script to manage docker volumes (list, cat, delete or copy from and to volumes)
This file contains 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
#!/usr/bin/env bash | |
export CMD=$1 | |
export VOLUME=$2 | |
export FILE=$3 | |
if [ "$CMD" == "" ] || [ "$VOLUME" == "" ] || [ "$FILE" == "" ]; then | |
echo "Missing argument/s: $0 [ls|rm|get|put] volume file" | |
exit | |
fi | |
export BASE=`basename $FILE` | |
if [ "$CMD" == "ls" ]; then | |
docker run --rm -i -v "$VOLUME:/tmp/myvolume" busybox ls -la /tmp/myvolume/$FILE | |
elif [ "$CMD" == "cat" ]; then | |
docker run --rm -i -v "$VOLUME:/tmp/myvolume" busybox cat /tmp/myvolume/$FILE | |
elif [ "$CMD" == "rm" ]; then | |
docker run --rm -i -v "$VOLUME:/tmp/myvolume" busybox rm -rf /tmp/myvolume/$FILE | |
elif [ "$CMD" == "get" ]; then | |
docker run --rm -i -v "$VOLUME:/tmp/myvolume" -v "$PWD:/tmp/local" busybox cp /tmp/myvolume/$FILE /tmp/local/$BASE | |
elif [ "$CMD" == "put" ]; then | |
docker run --rm -i -v "$VOLUME:/tmp/myvolume" -v "$PWD:/tmp/local" busybox cp /tmp/local/$BASE /tmp/myvolume/$FILE | |
else | |
echo Command must be get, por, ls, rm, cat | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment