Elastic Beanstalk / Docker – 没有这样的文件或目录package.json

我正在使用Elastic beanstalk来启动一个使用nodejs容器和mongodb容器的应用程序。 我已经为节点networking应用程序创build了自己的图像,并且我可以使用此图像在本地创build容器,并且在EC2实例上创build容器,而不存在问题。 当使用Beanstalk启动应用程序时,CMD“npm run prod”无法find我的package.json文件。 以下是关于我的设置和问题的一些注意事项:

  • 使用Elastic Beanstalk多容器Docker环境
  • 在两个图像中使用Dockerrun.aws.json文件:在dockerhub上托pipe的Mongo和自定义nodejs Web应用程序图像
  • 我可以把图像拉下来,用'Docker run npm run prod'运行它,它可以工作(本地和EB创build的EC2实例)
  • 当EB尝试启动图像(使用相同的命令),它出错了,并说它无法findpackage.json(详情见下面的错误)。

我不确定是否对Elastic Beanstalk的工作原理有误解,或者是否有其他缺失的地方。

Dockerrun.aws.json文件(图像名称和环境variables被删除):

{ "AWSEBDockerrunVersion": 2, "volumes": [ { "name": "mongo-vol", "host": { "sourcePath": "/var/app/mongo-vol" } }, { "name": "web-vol", "host": { "sourcePath": "/var/app/web-vol" } } ], "containerDefinitions": [ { "name": "mongo", "image": "mongo:3.4", "essential": false, "memory": 128 }, { "name": "web", "image": "<IMAGE NAME>", "essential": true, "memory": 128, "portMappings": [ { "hostPort": 80, "containerPort": 3000 } ], "links": [ "mongo" ], "mountPoints": [ { "sourceVolume": "web-vol", "containerPath": "/starter", "readOnly": false } ] } ] } 

节点Web应用程序的Dockerfile:

 FROM node:6-slim COPY . /starter COPY package.json /starter/package.json WORKDIR /starter ENV NODE_ENV production RUN yarn install --production RUN npm install forever -g CMD npm run prod EXPOSE 8888 

来自package.json的npm脚本:

 "prod": "forever app.js", 

来自docker容器的错误日志:

 npm info it worked if it ends with ok npm info using npm@3.10.10 npm info using node@v6.11.2 npm ERR! Linux 4.9.43-17.38.amzn1.x86_64 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "prod" npm ERR! node v6.11.2 npm ERR! npm v3.10.10 npm ERR! path /starter/package.json npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall open npm ERR! enoent ENOENT: no such file or directory, open '/starter/package.json' npm ERR! enoent ENOENT: no such file or directory, open '/starter/package.json' npm ERR! enoent This is most likely not a problem with npm itself npm ERR! enoent and is related to npm not being able to find a file. npm ERR! enoent npm ERR! Please include the following file with any support request: npm ERR! /starter/npm-debug.log 

将CMD更改为bash后的错误日志-c“pwd && ls -alh && npm run prod”

 /starter total 12K drwxr-xr-x 2 root root 4.0K Sep 1 16:01 . drwxr-xr-x 22 root root 4.0K Sep 1 16:01 .. -rw-r--r-- 1 root root 885 Sep 1 16:01 npm-debug.log npm info it worked if it ends with ok npm info using npm@3.10.10 npm info using node@v6.11.2 npm ERR! Linux 4.9.43-17.38.amzn1.x86_64 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "prod" npm ERR! node v6.11.2 npm ERR! npm v3.10.10 npm ERR! path /starter/package.json npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall open npm ERR! enoent ENOENT: no such file or directory, open '/starter/package.json' npm ERR! enoent ENOENT: no such file or directory, open '/starter/package.json' npm ERR! enoent This is most likely not a problem with npm itself npm ERR! enoent and is related to npm not being able to find a file. npm ERR! enoent npm ERR! Please include the following file with any support request: npm ERR! /starter/npm-debug.log 

在容器定义中,在mountPoints下,'/ starter'的containerPath值覆盖了已经在/ starter中的数据。 通过改变价值,应用程序能够开始。

导致问题的容器定义:

  "mountPoints": [ { "sourceVolume": "web-vol", "containerPath": "/starter", "readOnly": false } 

修改的容器定义:

  "mountPoints": [ { "sourceVolume": "web-vol", "containerPath": "/web-data", "readOnly": false }