Last active
January 26, 2020 02:24
-
-
Save leehanchung/f447efe7bcf836d6ac094f576d2d65cd to your computer and use it in GitHub Desktop.
Shell script for pushing Docker images to ECR
This file contains 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 | |
IMAGE_NAME={name your local Docker image here} | |
REGION=$(aws configure get region) | |
ACCOUNT=$(aws sts get-caller-identity --query Account --output text) | |
# If the ECS repository doesn't exist, creates it. | |
aws ecr create-repository --repository-name ${IMAGE_NAME} > /dev/null 2>&1 | |
# ECR requires the image name to be in this format: | |
REPOSITORY_NAME=${ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com/${IMAGE_NAME}:latest | |
# Tags the image with the expect ECR format | |
docker tag ${IMAGE_NAME} ${REPOSITORY_NAME} | |
# Allows docker access to ECR | |
$(aws ecr get-login --no-include-email) | |
# pushes the image to ECR | |
docker push ${REPOSITORY_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment