skip to Main Content

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?

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. The ecs context in docker 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):

    export ACCOUNTNUMBER=<your account>
    export MYREGION=<your region>
    aws ecr get-login-password --region $MYREGION | docker login --password-stdin --username AWS $ECR_ECSWORKER_REPO_URI 
    docker context use default
    docker compose build
    docker compose push
    docker context use myecscontext
    docker compose up
    

    [the above assumes the myecscontext context has already been created with docker context create ecs myecscontext]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search