Skip to content

Instantly share code, notes, and snippets.

@slavanap
Last active April 13, 2018 07:25
Show Gist options
  • Save slavanap/521f9e23114a12071bafc632cdcd165f to your computer and use it in GitHub Desktop.
Save slavanap/521f9e23114a12071bafc632cdcd165f to your computer and use it in GitHub Desktop.
Copy contents of CONTAINER volumes to DEST_FOLDER
# 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