docker-compose push image to aws ecr

Viewed 24230

is it possible to have docker-compose both build an image and push it to a remote repo? right now I do the

docker-compose

build then I do

docker-compose config --services

loop through the names reconstruct the imagename and the tag, then do

docker push blah

Seems like there mush be a way to just ask it to push as well.

2 Answers

First you need to generate a login for AWS ECR using the aws ecr get-login-password command. In bash I did:

$ eval $(aws ecr get-login-password)

Then for each image, ecr requires you to create a repository before pushing the image.

In my docker-compose.yml file I have a series of services along the lines of:

version: '3'
services:
  scheduler:
    image: ${DOCKER_REGISTRY}/pipeline_scheduler
    build:
      context: ../
      dockerfile: ./docker/scheduler/Dockerfile
   startup:
     image: ${DOCKER_REGISTRY}/pipeline_setup
     build:
       context: ../
       dockerfile: ./docker/startup/Dockerfile
    # etc...

In my .env file I set DOCKER_REGISTRY to be the amazon registry location:

DOCKER_REGISTRY=919057965832.dkr.ecr.us-east-1.amazonaws.com

To create the repositories in ecr (using bash again):

$ for r in $(grep 'image: \${DOCKER_REGISTRY}' docker-compose.yml | sed -e 's/^.*\///')
> do
>  aws ecr create-repository --repository-name "$r"
> done

(The output will show the registry info including the account and region, so you can check/set your .env file at this point if you like).

Then you can build and push the images in the usual way:

$ docker-compose build
$ docker-compose push
 
Related