in Uncategorized

Publishing a Docker image to Amazon ECR

How to push a container

Let me share a few quick steps on how you can push your Docker container to the Amazon ECR repository.

Step1: Creating a repository

The first step is to create a repository where your Docker container can be pushed to. A single repository can contain multiple versions of a docker container with a maximum of 2k versions. For different docker containers, you would create individual repositories.

In order to create a repository, you may create it directly from AWS Dashboard webui or use the AWS CLI like here. Let’s say our test-svc docker container let’s just run this command using the AWS CLI:

1
aws ecr create-repository --repository-name test-svc

Step2: Logging in to ECR

In order to be able to push containers via Docker, you need to login to the AWS ECR repository. You can do this by running this AWS CLI:

1
aws ecr get-login

This will give an output something like this:

1
docker login -u AWS -p password -e none https://aws_account_id.dkr.ecr.eu-west-1.amazonaws.com

You need to take that output and run it in the console to do the actual login so that you can push your container.

Step3: Pushing the container

Now that we are authenticated we can start pushing the docker container, let’s make sure that we tag the container we want to push first:

1
docker tag test-svc:latest aws_account_id.dkr.ecr.eu-west-1.amazonaws.com/test-svc:latest

And after this we push the container as following:

1
docker push aws_account_id.dkr.ecr.eu-west-1.amazonaws.com/test-svc:latest

Note: Please make sure to replace aws_account_id with your actual AWS account id. This repository URL with the account ID is also returned when your repository was created in Step 1.

Hope the above helps for people that want to publish their Docker containers to AWS ECR ? If you have any questions do not hesitate to reach out to me via the different channels.