I’m trying to set up deployment where on docker compose up
command it would build necessary images, push them to ECR and launch everything on ECS.
What I’ve done so far.
- Created and switched to aws context:
docker context create ecs aws
docker context use aws
- Created
docker-compose.yml
file:
version: '3.9'
services:
frontend:
build: ./frontend
image: <my_aws_id>.dkr.ecr.<region>.amazonaws.com/frontend:latest
backend:
build: ./backend
image: <my_aws_id>.dkr.ecr.<region>.amazonaws.com/backend:latest
nginx:
build: ./nginx
image: <my_aws_id>.dkr.ecr.<region>.amazonaws.com/nginx:latest
ports:
- 80:80
After reading a bunch of manuals, to my understanding, command docker compose up
should:
- Build images
- Push them to ECR
- Create cluster and necessary tasks on ECS
- Launch containers
Instead I’m having error that telling me that those images are not found. Yes, my ECR repo is empty, but I expect docker compose up
to build and push images to that repo, not just try to get them from ECR.
What am I doing wrong?
2
Answers
The purpose of the command is to bring the services
up
locally:Depending on context it may as well build and pull images, create or update containers, and of course, start services, but it does not
push
. If you intend to use docker-compose to push images, I suggest you manually run build and push commands:The
ecs
context indocker compose
does not allow to build/push. As of today you need to dance slightly between context to achieve what you are trying to do. This is an example (embedded into a completely different project) that shows the process.In a nutshell (and for posterity):
[the above assumes the
myecscontext
context has already been created withdocker context create ecs myecscontext
]