Created
May 5, 2026 13:53
-
-
Save ferraridavide/e61e465c3911a2bc33a5da72837f2d2d to your computer and use it in GitHub Desktop.
Extract fs from ECR
This file contains hidden or 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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [[ $# -ne 1 ]]; then | |
| echo "Usage: $0 <image>" | |
| echo "Example: $0 806377085208.dkr.ecr.eu-central-1.amazonaws.com/my-repo:latest" | |
| exit 1 | |
| fi | |
| IMAGE="$1" | |
| REGISTRY="${IMAGE%%/*}" | |
| REGION="$(echo "$REGISTRY" | sed -E 's#^[0-9]+\.dkr\.ecr\.([^.]+)\.amazonaws\.com$#\1#')" | |
| if [[ "$REGISTRY" == "$IMAGE" || -z "$REGION" || "$REGION" == "$REGISTRY" ]]; then | |
| echo "Could not parse ECR registry/region from image: $IMAGE" | |
| exit 1 | |
| fi | |
| aws ecr get-login-password --region "$REGION" | docker login --username AWS --password-stdin "$REGISTRY" | |
| docker pull "$IMAGE" | |
| CONTAINER_ID="$(docker create "$IMAGE")" | |
| docker cp "${CONTAINER_ID}":/ ./image-rootfs | |
| docker rm "$CONTAINER_ID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment