0
我正在使用Elastic beanstalk启动一个应用程序,使用nodejs容器和mongodb容器。我已经为节点网络应用程序创建了自己的图像,并且我可以使用此图像在本地创建容器,并在EC2实例上创建容器,而不存在任何问题。当使用Beanstalk启动应用程序时,CMD“npm run prod”无法找到我的package.json文件。这里是我的设置和问题谈几点注意事项:Elastic Beanstalk/Docker - 没有这样的文件或目录package.json
- 采用弹性魔豆多包装泊坞环境
- 使用Dockerrun.aws.json有两个图片文件:蒙戈和定制托管的NodeJS上dockerhub web应用程序图像
- 我可以拉下图片并使用'Docker run npm run prod'运行它(它在本地和EB创建的EC2实例上)
- 当EB尝试启动图像(使用相同的命令)时,它出错了,并且说它找不到package.json(详情见下面的错误)。
我不确定我是否对Elastic Beanstalk的工作原理有误解,或者是否有其他缺失的东西。
Dockerrun.aws.json文件(图像名和env乏移除):
{
"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节点网络应用程序:
"prod": "forever app.js",
:从的package.json
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
NPM脚本
来自码头集装箱的错误日志:
改变CMD打坏-c后npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
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
错误日志 “PWD & & LS -alh & & NPM运行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 [email protected]
npm info using [email protected]
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运行刺”'。在这些更改之后发布新日志 –
我向帖子添加了错误日志。它显示该文件不存在。根本没有文件存在。如果我SSH入EC2实例并运行Docker运行-it bash,然后在ls in/starter中存在这些文件。再次,我不确定我是否在这里误解了某些东西,但这对我来说很奇怪。 –
如果我ssh进入EC2实例并运行sudo docker run bash -c“pwd && ls -alh && npm run prod”它可以工作,并且所有文件都存在。非常困惑 –