Mongodb 在elastic beanstalk上使用dockrun.aws.json在mongo contianer启动时创建用户

Mongodb 在elastic beanstalk上使用dockrun.aws.json在mongo contianer启动时创建用户,mongodb,amazon-web-services,docker,docker-compose,amazon-elastic-beanstalk,Mongodb,Amazon Web Services,Docker,Docker Compose,Amazon Elastic Beanstalk,我正在尝试在elastic beanstalk上部署一个多容器应用程序。 该应用程序由三个服务组成: 法斯塔皮 蒙哥达 雷迪斯 我的docker compose文件如下所示: version: "3" services: web: image: pushpvashisht/web:latest environment: - MONGO_HOST=${MONGO_HOST} - REDIS_HOST=${REDIS_HOST}

我正在尝试在elastic beanstalk上部署一个多容器应用程序。 该应用程序由三个服务组成:

  • 法斯塔皮
  • 蒙哥达
  • 雷迪斯
  • 我的docker compose文件如下所示:

    version: "3"
    services:
      web:
        image: pushpvashisht/web:latest
        environment:
          - MONGO_HOST=${MONGO_HOST}
          - REDIS_HOST=${REDIS_HOST}
        depends_on:
          - mongo
          - redis
        ports:
          - "8000:8000"
        volumes:
          - /mnt2/web-logs/:/web-logs/
      mongo:
        image: mongo:latest
        environment:
          - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
          - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
          - MONGO_INITDB_DATABASE=example
        ports:
          - "27017:27017"
        volumes:
          - /mnt2/mongo_data:/data/db/
          - ./src/helper_scripts/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
      redis:
        image: redis:latest
        ports:
          - "6379:6379"
        volumes:
          - /mnt2/redis_data:/data
    
    为mongo服务安装的卷(./src/helper_scripts/mongo init.js:/docker entrypoint initdb.d/mongo init.js:ro)用于为“示例”数据库创建用户

    mongo-init.js:

    db.createUser(
        {
            user: "admin",
            pwd: "admin",
            roles: [
                {
                    role: "readWrite",
                    db: "example"
                }
            ]
        }
    );
    
    如何将此docker compose文件转换为Dockerrun.aws.json文件,以便在elastic beanstalk上部署应用程序

    关于这些文件,我写了很多:

    {
        "AWSEBDockerrunVersion": 2,
        "containerDefinitions": [
            {
                "name": "web",
                "image": "pushpvashisht/web:latest",
                "essential": true,
                "environment": [
                    {
                        "name": "MONGO_HOST",
                        "value": "${MONGO_HOST}"
                    },
                    {
                        "name": "REDIS_HOST",
                        "value": "${REDIS_HOST}"
                    }
                ],
                "links": [
                    "mongo",
                    "redis"
                ],
                "portMappings": [
                    {
                        "containerPort": 8000,
                        "hostPort": 8000
                    }
                ],
                "mountPoints": [
                    {
                        "containerPath": "/web-logs/",
                        "sourceVolume": "Mnt2Web-Logs"
                    }
                ]
                "memory": 128
            },
            {
                "name": "mongo",
                "image": "mongo:latest",
                "essential": true,
                "environment": [
                    {
                        "name": "MONGO_INITDB_ROOT_USERNAME",
                        "value": "${MONGO_INITDB_ROOT_USERNAME}"
                    },
                    {
                        "name": "MONGO_INITDB_ROOT_PASSWORD",
                        "value": "${MONGO_INITDB_ROOT_PASSWORD}"
                    },
                    {
                        "name": "MONGO_INITDB_DATABASE",
                        "value": "example"
                    }
                ],
                "portMappings": [
                    {
                        "containerPort": 27017,
                        "hostPort": 27017
                    }
                ],
                "mountPoints": [
                    {
                        "containerPath": "/data/db/",
                        "sourceVolume": "Mnt2Mongo_Data"
                    },
                    {
                        "containerPath": "/docker-entrypoint-initdb.d/mongo-init.js",
                        "sourceVolume": "_SrcHelper_ScriptsMongo-Init_Js"
                    }
                ],
                "memory": 128
            },
            {
                "name": "redis",
                "image": "redis:latest",
                "essential": true,
                "portMappings": [
                    {
                        "containerPort": 6379,
                        "hostPort": 6379
                    }
                ],
                "mountPoints": [
                    {
                        "containerPath": "/data",
                        "sourceVolume": "Mnt2Redis_Data"
                    }
                ],
                "memory": 256
            }
        ],
        "volumes": [
            {
                "host": {
                    "sourcePath": "/mnt2/web-logs/"
                },
                "name": "Mnt2Web-Logs"
            },
            {
                "host": {
                    "sourcePath": "/mnt2/mongo_data"
                },
                "name": "Mnt2Mongo_Data"
            },
            {
                "host": {
                    "sourcePath": "./src/helper_scripts/mongo-init.js"
                },
                "name": "_SrcHelper_ScriptsMongo-Init_Js"
            },
            {
                "host": {
                    "sourcePath": "/mnt2/redis_data"
                },
                "name": "Mnt2Redis_Data"
            }
        ]
    }