Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose push image to aws ecr

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.

like image 291
Raif Avatar asked May 18 '17 16:05

Raif


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
 
like image 197
akosky Avatar answered Sep 18 '22 12:09

akosky


Check out this snippet from the docs at https://docs.docker.com/compose/compose-file/compose-file-v3/#build:

If you specify image as well as build, then Compose names the built image with the webapp and optional tag specified in image:

build: ./dir
image: webapp:tag

This will result in an image named webapp and tagged tag, built from ./dir.

You could at least prepend the image repository in the image name. Then you would should be able to use docker-compose push with newer versions of Docker Compose.

like image 41
Andy Shinn Avatar answered Sep 20 '22 12:09

Andy Shinn