我使用Elastic beanstalk使用nodejs容器和mongodb容器启动应用程序。我已经为节点web应用程序创建了自己的映像,并且我能够使用此映像在本地创建容器,并且在EC2实例上创建容器而没有任何问题。当使用Beanstalk来启动应用程序时,CMD“npm run prod”无法找到我的package.json文件。以下是关于我的设置和问题的一些注意事项:
我不确定我是否对Elastic Beanstalk的工作方式存在误解,或者我是否还有其他错误。
Dockerrun.aws.json文件(图片名称和env vars已删除):
{
"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
}
]
}
]
}
节点网络应用程序的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&amp;&amp; ls -alh&amp;&amp; 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
答案 0 :(得分:0)
在容器定义中,在mountPoints下,'/ starter'的containerPath值超过了写入/ starter中已经存在的数据。通过更改值,应用程序就可以启动了。
导致问题的容器定义:
"mountPoints": [
{
"sourceVolume": "web-vol",
"containerPath": "/starter",
"readOnly": false
}
修改后的容器定义:
"mountPoints": [
{
"sourceVolume": "web-vol",
"containerPath": "/web-data",
"readOnly": false
}