'Initialise mongodb container in ECS task definition with ansible

I have deployed and initialised locally a mongo container with docker-compose:

services:
  mongo-db:
    image: mongo:latest
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: '${DB_USER}'
      MONGO_INITDB_ROOT_PASSWORD: '${DB_PASSWORD}'
    ports:
      - '27017:27017'
    networks:
      - backend-network
    volumes:
      - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - mongodb-data-local:/data
volumes:
   mongodb-data-local: 

Now I am trying to deploy the same container in ECS with this task definition:

- name: Create task definition
  community.aws.ecs_taskdefinition:
    containers:
    - name: mongo-db
      essential: true
      image: "mongo"
      # cpu: 128
      # memory: 340
      environment: 
        - name: MONGO_INITDB_ROOT_USERNAME
          value: "{{ lookup('env', 'DB_USER') }}"
        - name: MONGO_INITDB_ROOT_PASSWORD
          value: "{{ lookup('env', 'DB_PASSWORD') }}"
      mountPoints:
        - containerPath: ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
          sourceVolume: mongodb-data-local
      portMappings:
      - containerPort: 27017
        hostPort: 27017
    volumes:
      - name: mongodb-data-local

the file init-mongo.js is in my local machine.

The ECS container stops with the following error:

Status reason CannotCreateContainerError: Error response from daemon: invalid volume specification: 'ecs-backend-task-22-mongodb-data-local-a8d2c78eb3eae18e9501:./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro'

Is it possible to initialise this container in the task definition? What am I missing? Thanks for any answer!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source