Nuxt js在Linux vm中启动,但不在Docker容器中启动,为什么?

问题描述 投票:1回答:1

从Linux的Windows子系统启动nuxt应用程序时,以及在Docker中启动同一应用程序时,我得到不同的结果。我已经在docker上安装了其他一些应用程序,所以我对这个概念并不陌生。

WSLenter image description here

正在监听连接

Docker

enter image description here

给我一个例外

FROM node:12.16

ENV APP_ROOT /code

RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}
#ADD . ${APP_ROOT}

RUN npm install
RUN npm build

EXPOSE 3000
ENV HOST 0.0.0.0
#CMD npm run dev
CMD tail -f /dev/null

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]~predev: [email protected]
6 info lifecycle [email protected]~dev: [email protected]
7 verbose lifecycle [email protected]~dev: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~dev: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/code/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle [email protected]~dev: CWD: /code
10 silly lifecycle [email protected]~dev: Args: [
10 silly lifecycle   '-c',
10 silly lifecycle   'cross-env NODE_ENV=development nodemon server/index.js --watch server'
10 silly lifecycle ]
11 info lifecycle [email protected]~dev: Failed to exec dev script
12 verbose stack Error: [email protected] dev: `cross-env NODE_ENV=development nodemon server/index.js --watch server`
12 verbose stack spawn ENOENT
12 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack     at ChildProcess.emit (events.js:311:20)
12 verbose stack     at maybeClose (internal/child_process.js:1021:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
13 verbose pkgid [email protected]
14 verbose cwd /code
15 verbose Linux 4.19.76-linuxkit
16 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
17 verbose node v12.16.1
18 verbose npm  v6.13.4
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error [email protected] dev: `cross-env NODE_ENV=development nodemon server/index.js --watch server`
23 error spawn ENOENT
24 error Failed at the [email protected] dev script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
docker npm nuxt.js
1个回答
0
投票

问题似乎是在创建docker映像时package.json文件中的错字。

您正在docker之外的脚本下运行。

跨环境NODE_ENV =开发nodemon服务器/index.js --watch服务器

在docker内部的脚本下运行。

跨环境NODE_ENV =开发nodemon服务器/index.js --watch aerver

服务器-> aerver

[您在构建docker映像时应检查package.json。

还有一点建议。在容器上工作时,应该使用dockers环境变量,而无需在容器上使用类似跨环境的软件包,这显然使调试问题变得更加困难。

所以您的dockerfile应该看起来像这样。

FROM node:12.16

ENV APP_ROOT /code

ENV NODE_ENV development

RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}
#ADD . ${APP_ROOT}

RUN npm install
RUN npm build

EXPOSE 3000
ENV HOST 0.0.0.0
CMD npm run dev

而且package.json中的开发脚本应如下所示。

nodemon服务器/index.js --watch服务器

编辑:由于屏幕不好而消除了错误的意见。

© www.soinside.com 2019 - 2024. All rights reserved.