我在 docker 中运行我的应用程序,但我的生产构建和启动脚本仅在 docker 环境中失败。尽管 node_env 开发在 docker 环境中运行良好。
这是我的脚本,它无法进行生产构建并启动服务器。我正在使用 nodemon 和 babel
"build:prod": {
"command": "babel ./src/server/ -d server --presets es2015,stage-2 && next build src",
"env": {
"NODE_ENV": "production"
}
},
"start:prod": {
"command": "PORT=3000 nodemon --watch ./src/server/ ./src/server/server.js --exec babel-node --presets es2015,stage-2",
"env": {
"NODE_ENV": "production"
}
}
但是当我在 docker 环境中给出相同的命令时:
FROM node:8-alpine
COPY package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app
WORKDIR /opt/app
ADD . /opt/app
RUN npm run build:prod
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
我在 docker 中收到以下错误:
> better-npm-run start:prod
site_1 |
site_1 | running better-npm-run in /opt/app
site_1 | Executing script: start:prod
site_1 |
site_1 | to be executed: PORT=3000 NODE_ENV=production nodemon --watch ./src/server/ ./src/server/server.js --exec babel-node --presets es2015,stage-2
site_1 | [nodemon] 1.17.3
site_1 | [nodemon] to restart at any time, enter `rs`
site_1 | [nodemon] watching: /opt/app/src/server/**/*
site_1 | [nodemon] starting `babel-node ./src/server/server.js --presets es2015,stage-2`
site_1 | false 'production'
site_1 | > Could not find a valid build in the '.next' directory! Try building your app with 'next build' before starting the server.
site_1 | [nodemon] app crashed - waiting for file changes before starting...
我将不胜感激,并且很高兴知道我做错了什么。