不显示内容时如何使用Docker为Nginx提供React App服务

时间:2019-09-25 22:23:49

标签: reactjs docker nginx

我正在尝试对我的React App进行Docker化,但是当我运行docker run -p 8080:80 <container-id>并访问192.168.99.100:8080时,除了空白页面,我什么也没得到。

我尝试实现this解决方案,但仍然看不到任何内容显示,唯一的区别是现在nginx服务器在GET请求之后返回了200个代码而不是404。

这是我的Dockerfile

FROM node:alpine as builder
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build

#/app/build <--- has all the stuff

FROM nginx
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html
#react-router fix
RUN rm -rf /etc/nginx/conf.d
COPY conf /etc/nginx

这是nginx的响应

192.168.99.1 - - [25/Sep/2019:22:17:35 +0000] "GET /patrickl13/personal-react-website/static/css/2.510409cd.chunk.css HTTP/1.1" 200 2568 "http://192.168.99.100:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" "-"
192.168.99.1 - - [25/Sep/2019:22:17:35 +0000] "GET /patrickl13/personal-react-website/static/css/main.082c09f4.chunk.css HTTP/1.1" 200 2568 "http://192.168.99.100:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" "-"
192.168.99.1 - - [25/Sep/2019:22:17:35 +0000] "GET /patrickl13/personal-react-website/static/js/2.5f2d90f6.chunk.js HTTP/1.1" 200 2568 "http://192.168.99.100:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" "-"
192.168.99.1 - - [25/Sep/2019:22:17:35 +0000] "GET /patrickl13/personal-react-website/static/js/main.bf6cb779.chunk.js HTTP/1.1" 200 2568 "http://192.168.99.100:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" "-"
192.168.99.1 - - [25/Sep/2019:22:17:35 +0000] "GET /patrickl13/personal-react-website/favicon.ico HTTP/1.1" 200 2568 "http://192.168.99.100:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" "-"

预期结果是可以像运行npm start

一样为网络应用提供服务

0 个答案:

没有答案