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