Created
March 26, 2024 12:41
-
-
Save scorpion1201/e78ea2e84220756ddee48611b4fee03b 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/sh | |
usage() { | |
echo "Usage: docker_volume <volume_name> <target_directory> [command] [command arguments...]" | |
} | |
help() { | |
echo "This script mounts <volume_name> to /volume, and <target_dir> to /data" | |
echo "in this container." | |
echo | |
echo "Example:" | |
echo " # List the contents of the volume directory in the container." | |
echo " docker_volume my_volume /target/dir" | |
echo | |
echo " # Use the 'ls' command to list all files in detailed format" | |
echo " in /data directory inside the container." | |
echo " docker_volume my_volume /target/dir ls -alF /data" | |
echo | |
echo " # Copy a file from the /data directory to the /volume directory" | |
echo " inside the container." | |
echo " docker_vol my_volume /target/dir cp /data/file1 /volume/file2" | |
} | |
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then | |
usage | |
echo | |
help | |
exit 1 | |
fi | |
if [ $# -lt 2 ]; then | |
usage | |
exit 1 | |
fi | |
VOLUME_NAME=$1 | |
TARGET_PATH=$2 | |
shift 2 | |
if [ ! -d "$TARGET_PATH" ]; then | |
mkdir -p $TARGET_PATH | |
fi | |
if [ $# -eq 0 ]; then | |
set -- ls -alF /volume | |
fi | |
docker run --rm --name file_transfer \ | |
-v $TARGET_PATH:/data \ | |
-v $VOLUME_NAME:/volume \ | |
busybox "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment