Last active
April 13, 2018 07:25
-
-
Save slavanap/521f9e23114a12071bafc632cdcd165f to your computer and use it in GitHub Desktop.
Copy contents of CONTAINER volumes to DEST_FOLDER
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
# Copy contents of CONTAINER volumes to DEST_FOLDER | |
# usage: volcp CONTAINER DEST_FOLDER | |
volcp() ( | |
set -e | |
if [[ -z "$2" ]]; then | |
echo "ERROR: Destination folder must be specified as second argument" >&2 | |
exit 1 | |
fi | |
echo " To mount volumes please run:" | |
echo "docker run \\" | |
docker inspect -f '{{json .Mounts}}' "$1" | jq '.[] | .Source, .Destination' | \ | |
while read Source; do | |
read Destination | |
Source=$(eval echo "$Source") | |
Destination=$(eval echo "$Destination") | |
mkdir -p "$2$Destination" | |
rmdir "$2$Destination" | |
cp -a "$Source" "$2$Destination" | |
echo " -v \"\$(pwd)$Destination:$Destination\" \\" | |
done | |
echo " ..." | |
) | |
# sudo -i | |
# source copy-docker-container-volumes.sh | |
# mkdir container_volumes | |
# volcp mycontainer container_volumes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment