How to store a Docker image on Amazon EC2 Container Registry (ECR)

 

Amazon announced some time ago their update to the already existing EC2 Container Service (ECS) that was then joined by ECR, allowing us to store our Docker images on a safe environment

At the time of writing, ECR is only available on the us-west-1 region (N.Virginia) although it’s been said it will expand into new regions during the year. In our case, even though we will deploy this image on eu-west-1 region (Ireland), we will store the image on us-west-1 so bear that in mind if you go to your AWS console and can’t find your image/deployment.

Now – let’s get our hands dirty 😀

STEP 1 – Create a Docker image
Over the coming weeks, I will write further on how to create a Docker image for an existing Ruby on Rails app, but for the purpose of this tutorial we will just use the following example that I’ve borrowed from Codeship:

You just need to create a new file called Dockerfile on your project’s root folder.
Once we’ve got a Dockerfile, our next step is to actually build our Docker image, for which we will start Docker QuickStart Terminal, go to our project’s folder and then issue:
docker build -t myapp .

 

STEP 2 – Push Our Image onto ECR
Now we are going to upload our image onto AWS ECR in order to store it. This will allow us to not only be able to share it using amazon’s infrastructure but to also deploy it in the future using ECS

First, we need a login signature so we can authenticate our Docker client to our EC Registry

or

(in case you have more than one AWS CLI profile installed).

Next, we will enter the command that it just returned that will be similar to:

And we’re in! Our next step is to tag our Docker image:

And push it onto ECR

We’re done!

Hope you found this useful, did you have any problems with it? Have you got any extra information to add onto this post? Let me know in the comments below 🙂

    Some extra info:

  • http://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-basics.html
  • http://docs.aws.amazon.com/AmazonECR/latest/userguide/ECR_GetStarted.html

Leave a Reply