我使用Elastic beanstalk使用nodejs容器和mongodb容器启动应用程序 . 我已经为节点web应用程序创建了自己的映像,并且我能够使用此映像在本地创建容器,并且在EC2实例上创建容器而没有任何问题 . 当使用Beanstalk来启动应用程序时,CMD“npm run prod”无法找到我的package.json文件 . 以下是有关我的设置和问题的一些注意事项:
-
使用Elastic Beanstalk Multicontainer Docker环境
-
使用带有两个图像的Dockerrun.aws.json文件:Mongo,以及在dockerhub上托管的自定义nodejs web app图像
-
我可以将图像拉下来并使用'Docker run npm run prod'运行它并且它可以工作(本地和EB创建的EC2实例)
-
当EB尝试启动图像时(使用相同的命令),它出错并说它找不到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
}
]
}
]
}
节点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
1 回答
在容器定义中,在mountPoints下,'/ starter'的containerPath值过度写入已经位于/ starter中的数据 . 通过更改值,应用程序能够启动 .
导致问题的容器定义:
修改容器定义: