我有一个简单的 React 应用程序创建create-react-app
在本地主机上运行良好。我现在正在尝试 Dockerify 该应用程序。这是我的 package.json:
{
"name": "yeet",
"version": "0.1.0",
"engines": {
"node": "12.x"
},
"scripts": {
"client": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start": "node server.js",
"production": "npm run build && npm run start"
},
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.21.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-session": "^1.17.1",
"mongoose": "^5.10.13",
"mysql": "^2.18.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"devDependencies": {
"babel-core": "*",
"babel-loader": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"babel-preset-stage-0": "*"
},
"babel": {
"presets": [
"@babel/env",
"@babel/react",
"babel-preset-stage-0"
],
"env": {
"start": {
"presets": [
"@babel/env",
"@babel/react",
"babel-preset-stage-0"
]
}
}
}
}
这是我的 Dockerfile:
# Specify base image
FROM node:12.19.0-alpine3.10
# Specify app location in host
WORKDIR /app
# Copy the dependency list
COPY package.json ./
# Install app dependencies
RUN npm install
# Copy app code to host
COPY . .
# Open specified port
EXPOSE 3000:3000
# Start the app
CMD ["npm", "run", "production"]
我用以下方法构建图像:
docker build --tag yeet .
然后我将图像作为容器运行:
docker run --publish 3000:3000 yeet
这会抛出:
$ docker run --publish 3000:3000 还
y[电子邮件受保护] /cdn-cgi/l/email-protection生产/应用程序
npm run build && npm run start
[电子邮件受保护] /cdn-cgi/l/email-protection构建/应用程序
反应脚本构建
/app/node_modules/eslint-webpack-plugin/dist/options.js:62(0,
_schemaUtils.default)(_options.default, 选项, {
^
类型错误:(0,_schemaUtils.default)不是函数
在 getOptions (/app/node_modules/eslint-webpack-plugin/dist/options.js:62:28)
在新的 ESLintWebpackPlugin (/app/node_modules/eslint-webpack-plugin/dist/index.js:30:44)
在 module.exports (/app/node_modules/react-scripts/config/webpack.config.js:749:7)
在对象。 (/app/node_modules/react-scripts/scripts/build.js:67:16)
在 Module._compile (内部/modules/cjs/loader.js:1015:30)
在 Object.Module._extensions..js (内部/模块/cjs/loader.js:1035:10)
在 Module.load (内部/modules/cjs/loader.js:879:32)
在 Function.Module._load (内部/modules/cjs/loader.js:724:14)
在 Function.executeUserEntryPoint [作为 runMain] (内部/模块/run_main.js:60:12)
在内部/main/run_main_module.js:17:47 npm 错误!代码 ELIFECYCLE npm 错误! errno 1 npm 错误![电子邮件受保护] /cdn-cgi/l/email-protection build: react-scripts build
npm 错误!退出状态 1 npm ERR! npm 错误!失败于[电子邮件受保护] /cdn-cgi/l/email-protection构建脚本。 npm 错误!这可能不是 npm 的问题。那里
上面可能是额外的日志输出。
npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!
/root/.npm/_logs/2020-11-07T12_47_03_927Z-debug.log npm 错误!代码
ELIFECYCLE npm 错误! errno 1 npm 错误![电子邮件受保护] /cdn-cgi/l/email-protection生产:npm run build && npm run start
npm 错误!退出状态 1 npm ERR! npm 错误!
失败于[电子邮件受保护] /cdn-cgi/l/email-protection制作脚本。 npm 错误!这是
可能不是 npm 的问题。可能有额外的日志记录
输出如上。
npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!
/root/.npm/_logs/2020-11-07T12_47_03_923Z-debug.log
有人看到我做错了什么吗?任何指示都会非常有帮助!