Search code examples
dockerdocker-composeamazon-ecsamazon-ecr

Docker compose won't push to ECR


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.

  1. Created and switched to aws context:
docker context create ecs aws
docker context use aws
  1. 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:

  1. Build images
  2. Push them to ECR
  3. Create cluster and necessary tasks on ECS
  4. 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?


Solution

  • The purpose of the command is to bring the services up locally:

    ❯ docker-compose --help
      ...
      create             Create services
      push               Push service images
      start              Start services
      up                 Create and start containers
    

    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:

    docker-compose build
    docker-compose push