Skip to content

Instantly share code, notes, and snippets.

@lhns
Last active October 22, 2025 11:56
Show Gist options
  • Select an option

  • Save lhns/04e2ed582d89ae27e3da05eae0dc5fae to your computer and use it in GitHub Desktop.

Select an option

Save lhns/04e2ed582d89ae27e3da05eae0dc5fae to your computer and use it in GitHub Desktop.
#!/bin/sh
copy_to_volume() {
src="$1"
dst="$2"
volume=$(echo "$dst" | cut -d':' -f1)
path=$(echo "$dst:" | cut -d':' -f2)
docker volume create "$volume"
container_id=$(docker create -v "$volume:/vol" "$(echo -e 'FROM scratch\nENTRYPOINT ["/"]' | docker build -q -)")
err=0
docker cp "$src" "$container_id:/vol/${path#/}" >/dev/null || err=$?
docker rm "$container_id" >/dev/null
return "$err"
}
copy_to_volume "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment