11

I am trying to deploy a nodejs docker-compose app into aws ecs, here is how my docker compose file looks -

version: '3.8'

services:
 sampleapp:
  image: jeetawt/njs-backend
  build:
   context: .
  ports:
   - 3000:3000
  environment:
   - SERVER_PORT=3000
   - CONNECTIONSTRING=mongodb://mongo:27017/isaac
  volumes:
   - ./:/app
  command: npm start

 mongo:
  image: mongo:4.2.8
  ports:
   - 27017:27017
  volumes:
   - mongodb:/data/db
   - mongodb_config:/data/configdb
volumes:
 mongodb:
 mongodb_config:

However when i try to run it using docker compose up after creating ecs context, it throws below error -

WARNING services.build: unsupported attribute        
ECS Fargate does not support bind mounts from host: incompatible attribute

I am not specifying any where that I would like to use Fargate for this. Is there any way I can still deploy the application using ec2 instead of Fargate?

Jeet
  • 5,569
  • 8
  • 43
  • 75
  • 2
    what did you finally end up doing? – jayasurya_j Aug 01 '22 at 15:16
  • 1
    I has a similar problem and eventually ended up using named volumes instead of bind mounts. –  Dec 02 '22 at 18:23
  • "Bind mounts are supported for tasks that are hosted on both Fargate and Amazon EC2 instances." - from https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bind-mounts.html – declension Jan 06 '23 at 17:33

2 Answers2

5

Default mode is Fargate. You presumably have not specified an ecs cluster with ec2 instances in your run command.

Your docker compose has a bind mount so your task would need to get deployed to an instance where the mount would work.

This example discusses deploying to an ec2 backed cluster. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-cli-tutorial-ec2.html

1

Fargate is the default and there is no way to tell it that you want to deploy on EC2 instead. There are however situations where we have to deploy on EC2 when Fargate can't provide the required features (e.g. GPUs).

If you really really need to use bind mounts and need an EC2 instance you may use this trick (I haven't done it so I am basically brainstorming here):

  • configure your task to use a GPU (see examples here)
  • Convert your compose using docker compose convert
  • Manually edit the CFN template to use a different instance type (to avoid deploying a GPU based instance with its associated price)
  • Deploy the resulting CFN template.

You may even be able to automate this with some sed circus if you really need to.

As I said, I have not tried it and I am not sure how viable this could be. But it wouldn't be too complex I guess.

mreferre
  • 5,464
  • 3
  • 22
  • 29