#!/bin/bash -eu # ecr_get_image.sh: get and unpack a docker image from ECR REPO_NAME="$1" TAG="${2:-latest}" IMAGE="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO_NAME:$TAG" docker pull "$IMAGE" id=$(docker create "$IMAGE") docker export $id -o "$REPO_NAME.tar" docker inspect $id > "$REPO_NAME.json" docker rm $id dir="$REPO_NAME.$TAG" if [ -d "$dir" ]; then confirm rm -rf "$dir" fi mkdir -p "$dir" tar -xf "$REPO_NAME.tar" -C "$dir" rm "$REPO_NAME.tar" docker rmi "$IMAGE" # docker system prune -a