简体   繁体   中英

NodeJS Multicontainer Docker on Elastic Beanstalk

I have a NodeJS application that communicates with mongodb. Both services should run on Elastic Beanstalk in a "multicontainer" Docker container. It seams that the mongodb service runs through and works but my NodeJS service doesn't start. It produces empty log files and the server is not available.

I am deploying the container via EB CLI. Starting everything locally via eb local run works fine but at the live environment the nodeJS part just doesn't start.

This is my Dockerrun.aws.json:

{
    "AWSEBDockerrunVersion": 2,
    "volumes": [
        {
            "name": "node",
            "host": {
                "sourcePath": "/var/app/current/node"
            }
        }
    ],
    "containerDefinitions": [
        {
            "environment": [
                {
                    "name": "MONGODB_DATABASE",
                    "value": "chat_service"
                }
            ],
            "image": "mongo",
            "memory": 128,
            "name": "mongo"
        },
        {
            "essential": true,
            "image": "node",
            "memory": 250,
            "name": "node",
            "mountPoints": [
                {
                    "sourceVolume": "node",
                    "containerPath": "/usr/src/app",
                    "sourcePath": "",
                    "readOnly": true
                }
            ],
            "portMappings": [
                {
                    "hostPort": 80,
                    "containerPort": 3000
                }
            ]
        }
    ]
}

And my Dockerfile:

FROM node:carbon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .
EXPOSE 3000

CMD [ "node", "index.js" ]

I'm very new to Docker, so maybe I forgot something. Neither the CLI nor in the AWS EB Console any errors are visible and the deployment is processed without an error.

I guess you are missing to tag and push & deploy your image.

  1. Tag your local image wrt your registry -

    $ docker tag node-app:latest a.dkr.ecr.us-east-1.amazonaws.com/node-app:latest

  2. Push your image -

    $ docker push a.dkr.ecr.us-east-1.amazonaws.com/node-app:latest

  3. Update JSON to use tagged image -

     "essential": true, "image": "a.dkr.ecr.us-east-1.amazonaws.com/node-app:latest", "memory": 250, 
  4. Deploy to Elasticbeanstalk -

    $ eb deploy $APP_ENV -l ${BUILD_TAG} --timeout 30

You can find ref. JSON file -

https://github.com/vivekyad4v/aws-elasticbeanstalk-multi-container

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM