<< Back to Blog List

Pushing your Docker image to Amazon ECR after CI

Posted by Manisha Sahasrabudhe on January 12, 2017

Amazon provides a hosted private registry for Docker images called EC2 Container Registry (ECR) as part of its container focused suite of services. Many of our customers seem to love the ECR and ECS (EC2 Container Service) combination to store and run their applications. Amazon ECR can be accessed by going to your AWS Management Console, selecting EC2 Container Service, and clicking on Repositories in the left sidebar. 

In this blog post, I will go through a simple scenario with a sample project where we enable a project for CI, build a docker image as part of the workflow, test the image, and then push it to Amazon ECR. In the next blog, we will then set up the rest of the Continuous Delivery pipeline for the sample application.

Let's get started...

Fork the demo projects from GitHub

1. sample-docker-push-registry repository contains code for the sample application. 

Create necessary integrations

2. Add an Amazon ECR integration by following instructions in the Adding an Account Integration section on the Amazon ECR integration page 

Set up Continuous Integration

Before you get started with setting up your deployments, let's set up CI for your sample application.

3. Enable your forked sample application for CI. 

  • From the Shippable dashboard, select your subscription from the Subscriptions dropdown at the top left of the dashboard. This should be the subscription where you forked the repository.
  • On the Subscription page, click on Enable Project in the left sidebar. If you have not enabled any projects on Shippable, you will be directly be taken to a page with a list of your repositories.
  • Find the forked repository and click on the Enable button.
  • If the repo is not shown in the list, click on the Sync button next to the Search box. This syncs your Shippable subscription with your Source Control. Find the samplenod project and enable it.

4. Take a look at the config file shippable.yml at the root of your forked sample app. The config is very simple- build a Docker image and push it to ECR. Make the following changes to shippable.yml:

  • Update the ecr integration with the Amazon ECR integration you created in step 2. 
integrations:
hub:
- integrationName: #your ECR integration name
type: ecr
  • Update IMAGE_NAME with your fully qualified repository name where you want to push the image. Please make sure the image repository you're pushing to exists on ECR. 
build:
ci:
- echo 'CI Running'
- export IMAGE_NAME= #e.g. 027746667844.dkr.ecr.us-east-1.amazonaws.com/sample-shipdemo

Commit and push the changes.

Run the build

Pushing the changes should trigger your build automatically. It will build the Docker image and push it to ECR.

You will find the image in your Amazon ECR Repositories list as shown below:

 amazon-ecr.png

In my next blog, we will see how to set up Continuous Delivery for this image, i.e. set up deployment into a series of environments like Dev, Test, Prod, create releases, and promote the versioned image through those environments.

Topics: Docker, docker registry, ECS, Amazon ECR, EC2, AWS