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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With