Skip to content

Instantly share code, notes, and snippets.

@ArloL
Created July 21, 2023 07:19
Show Gist options
  • Save ArloL/050e770cd3ee1f37a386017ddad95ba5 to your computer and use it in GitHub Desktop.
Save ArloL/050e770cd3ee1f37a386017ddad95ba5 to your computer and use it in GitHub Desktop.
docker copy
#!/bin/sh
set -o errexit
set -o nounset
set -o xtrace
CONTAINER_ID_FILE=$(mktemp -u)
cleanup() {
currentExitCode=$?
rm -f "${CONTAINER_ID_FILE}"
docker rm "${CONTAINER_ID}" || true
exit ${currentExitCode}
}
trap cleanup INT TERM EXIT
IMAGE_ID=$(cat "${1}")
docker create \
--cidfile "${CONTAINER_ID_FILE}" \
"${IMAGE_ID}"
CONTAINER_ID=$(cat "${CONTAINER_ID_FILE}")
docker cp "${CONTAINER_ID}:${2}" "${3}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment