【发布时间】:2020-07-25 10:30:49
【问题描述】:
我正在 Kubernetes 上使用 React 和 Node.js 构建一个 SPA。对于前端和后端服务,我有单独的服务和入口。我见过人们也使用 Nginx 来为 React 构建提供服务,但我发现下面的做法效果很好。
# Dockerfile.production
FROM node:8.7.0-alpine
RUN mkdir -p /usr/app/client
WORKDIR /usr/app/client
COPY package*.json /usr/app/client/
RUN npm install
RUN npm install -g serve
COPY . /usr/app/client
EXPOSE 3000
RUN npm run build
CMD ["serve", "-s", "build", "-l", "3000" ]
或者,我可以使用 Nginx 提供构建,如下所示。这似乎是“正确的方法”,但我不确定使用 serve npm 包的优势是什么,尽管它对我来说确实很hacky。似乎所有可以使用 Nginx 配置为应用程序提供服务的东西也可以在 Ingress 中完成,对吧?
server {
server_name example.com;
...
location ~ / {
root /var/www/example.com/static;
try_files $uri /index.html;
}
}
【问题讨论】:
标签: node.js reactjs nginx kubernetes dockerfile