我有一个简单的MERN堆栈SPA,我想为其构建一个docker映像。我一直在搜索一些教程,但是每个人都在构建一个dockerfile,客户端和服务器文件夹是同级而不是父级和子级,所以我想知道是否可行。我将create-react-app用于前端,后端是Nodejs,
文件结构如下:
-server/
- client/
- src/
- public/
- index.js
- package.json
- package-lock.json
- Dockerfile
- index.js
- package.json
- package-lock.json
这是我的server / package.json:
"scripts": {
"start": "node /app/index.js","server": "nodemon /app/index.js","client": "npm run start --prefix client","dev": "concurrently \"npm run server\" \"npm run client\""
}
我的client / package.json:
"scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
},"proxy": "http://localhost:5000"
我的服务器/ Dockerfile:
FROM node:10
# Set image metadata
LABEL version="1.0"
LABEL description="Johnny Node"
# Create app directory
WORKDIR /app
# install dependencies
COPY package*.json ./
RUN npm cache clean --force && npm install
# copy app source to image _after_ npm install so that
# application code changes don’t bust the docker cache of
# npm install step
COPY . .
COPY client/package*.json /app/client/
RUN cd /app/client && npm install && npm run build
# set application PORT and expose docker PORT,80 is what Elastic Beanstalk expects
EXPOSE 5000
CMD npm run dev
我遇到了一些奇怪的错误,例如找不到某些模块或npm ERR! client@0.1.0 build:react-scripts build
,不确定我的Dockerfile做错了什么。谢谢你!