From 8dbf855d569fcbf9ed1378a381c6e3e8638e3690 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 1 Aug 2019 19:40:30 -0400 Subject: [PATCH] feat: handle case where docker cp is run as non root and tries to chown the file This _may_ be cargo-cult, but its an easy way to handle any potential issues, so we'll include it regardless. --- plugins/common/functions | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 61a7bbb89..55561de88 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -394,8 +394,13 @@ copy_from_image() { trap "rm -rf '$TMP_FILE_COMMAND_OUTPUT' >/dev/null" RETURN local CID=$("$DOCKER_BIN" create "${DOCKER_CREATE_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "$IMAGE") - if ! "$DOCKER_BIN" cp "$CID:$SRC_FILE" "$TMP_FILE_COMMAND_OUTPUT"; then - "$DOCKER_BIN" rm -f "$CID" &>/dev/null + "$DOCKER_BIN" cp "$CID:$SRC_FILE" "$TMP_FILE_COMMAND_OUTPUT" 2>/dev/null || true + "$DOCKER_BIN" rm -f "$CID" &>/dev/null + + # docker cp exits with status 1 when run as non-root user when it tries to chown the file + # after successfully copying the file. Thus, we suppress stderr. + # ref: https://github.com/dotcloud/docker/issues/3986 + if [[ ! -s "$TMP_FILE_COMMAND_OUTPUT" ]]; then return 1 fi