Building docker images and pushing to ECR

Setup a server to build docker images and push to ECR

build docker image and push to AWS ECR

For creating a Deployment Server, take a new / existing machine running Ubuntu 18.04.

And follow these steps:

  • Install Docker
  • Setup aws cli
  • Change settings in your Django project to production
  • Build docker image and push it to ECR

1. Install docker

2. Install and setup aws cli

3. Change settings in your Django project to production

Best practice is to create a separate settings file for production environment viz. prod.py and extend your base settings.

from biostar.settings.base import *

# Replace settings and credentials below with the production ones

4. Build docker image and push to ECR

I've written a small deploy.sh script to build and push image to ECR.


if [ $# -lt 2 ]
        echo Please provide repository name and tag
        exit 1


        echo ================ Building $SOURCE_IMAGE ==================

        docker build -t "$SOURCE_IMAGE" .

        echo ================ Pushing $SOURCE_IMAGE to ECR ================

        eval $(aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 7813354292XX.dkr.ecr.us-east-1.amazonaws.com)

        docker push $SOURCE_IMAGE


It takes two parameters viz. repository name and image tag. The image will be built as per the Dockerfile and will be pushed properly to aws cloud registry.

Building webserver image -

./deploy.sh q10_web prod.1.0

Also build deployment script for other images. Eg. I created a deployment script for nginx image and stored in it conf folder.

cd conf/docker/ngnix

./deploy.sh q10_nginx prod.1.0

Verify on ECR dashboard whether the images are built and pushed properly.

page docker on aws • 31  views

Continue reading

Find answer to specific questions by searching them here. It's the best way to discover useful content.

Find more