[英]Elastic Beanstalk / Docker - No such file or directory package.json
我正在使用Elastic beanstalk使用nodejs容器和mongodb容器启动应用程序。 我已经为节点Web应用程序创建了自己的映像,并且能够使用该映像在本地以及在EC2实例上创建容器都没有问题。 但是,当使用Beanstalk启动应用程序时,CMD“ npm run prod”无法找到我的package.json文件。 以下是有关我的设置和问题的一些说明:
我不确定是否对Elastic Beanstalk的工作方式有误解,或者是否缺少其他内容。
Dockerrun.aws.json文件(图像名称和环境变量已删除):
{
"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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.