How Do You Upload a Docker Image to Amazon Elastic Container Registry?

Problem scenario
You created your own Docker image.  You want to upload it to a repository so it is available to other servers.  You want to upload a Docker image from your server into ECR (in AWS).  You do not know the name of the repository.  How do you do this?

Solution
Prerequisites

a.  This assumes that ECR has been set up.  If you need assistance, see this posting.
b.  This assumes you have your own Docker image configured locally one a server.  If you need assistance, see this posting.
c.  You must have the AWS CLI installed on a Linux server for authorization to your Elastic Container Registry.  If you need assistance with that, see this posting.

Overview
If you do not know the name of the Docker registry and you are using Amazon Elastic Container Registry (i.e., ECR), do the following to obtain the command to login.  You wil be able to push and pull images after you do steps 1 through 3.

Procedures
1.  Draft this command, but replace "us-east-6" with the region that the ECR is in:
(aws ecr get-login --no-include-email --region us-east-6)
2.  Run the above command that you drafted.  The (very long) result should be what you need to log into the ECR, but you may or may not need a "sudo " before that command.  This command should work on other servers besides the server it was originally displayed from.  
3.  The results from the above command are a draft of the next command you will run.  From the server that you want push the Docker image from, run the very long command to log into ECR (which may need a "sudo " before it).  
4.  Tag your Docker image.  Draft a command such as this, but do the replacements as they are described beneath it:

docker tag value1:value2 123456.dkr.ecr.us-west-6.amazonaws.com/reponame:value2

# Replace "value1" with the repository name of the Docker image (as seen in the results of a "docker images" command)
# Replace "value2" with the tag of the Docker image (as seen in the results of a "docker images" command)
# Replace "123456.dkr.ecr.us-west-6.amazonaws.com/reponame" with the ECR Repository URI (as seen in the results of a "aws ecr describe-repositories" command)

 5.  Run the command drafted above (after you have done the substitutions).

6.  Draft and execute a "docker push" command.  Remember to specify a destination Docker registry in the pull command.  It will look something like this: 
docker push 123456.dkr.ecr.us-west-6.amazonaws.com/reponame:value2

# Replace "value2" with the tag of the Docker image (as seen in the results of a "docker images" command)
# Replace "123456.dkr.ecr.us-west-6.amazonaws.com/reponame" with the ECR Repository URI (as seen in the results of a "aws ecr describe-repositories" command)

7.  You are done.  From another server properly configured (that has gone through steps 1 through 3 above), you can run the command in step #6 with "pull" instead of "push" to copy down the image to another Docker host.

Leave a comment

Your email address will not be published. Required fields are marked *