node.js - 运行 Docker 容器时无法显示我的 React UI
问题描述
我有一个想要容器化的 React 客户端和 Go 服务器应用程序。这是我第一次使用 Docker,所以我很难让它工作。我的 Dockerfile 看起来像我从本指南中获得的
# Build the Go API-
FROM golang:latest AS builder
ADD . /app
WORKDIR /app/server
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w" -a -o /main .
# Build the React application
FROM node:alpine AS node_builder
COPY --from=builder /app/client ./
RUN npm install
RUN npm run build
# Final stage build, this will be the container
# that we will deploy to production
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /main ./
COPY --from=node_builder /build ./web
RUN chmod +x ./main
EXPOSE 8080
CMD ./main
我的服务器代码采用PORT
环境变量来设置要监听的端口,因此我使用了以下 Docker 运行命令
docker run -p 3000:8080 --env PORT=8080 test1
:但是,当我转到localhost:3000时,我得到一个404 page not found响应,而不是我的 React 应用程序。我已经尝试了几种不同的 run 命令组合,但我似乎无法弄清楚如何让我的 UI 出现。这与我的 Dockerfile 有关还是我的运行命令缺少参数?或两者?
解决方案
推荐阅读
- python - 我应该怎么做才能更正此代码?作为输出,我必须获得无效输入,然后是最大值和最小值
- wordpress - Ninja Forms 服务器端验证不起作用
- c# - 具有多个 URL 的 HttpWebResponse 导致错误
- codenameone - 代号一逆向工程师安卓包
- c# - 找不到类型或命名空间名称“硬件”(您是否缺少 using 指令或程序集引用?)
- python - 如何在 python 中实现凯撒密码?
- bash - 为什么从 cli 运行 aws update-service 会导致弹出类似 vim 的窗口,需要一些输入?
- range - 如何在 Tableau 条形图中显示工资范围
- javascript - 在javascript中将onclick事件设置为ac# URL Action?
- javascript - 将地图功能导出到其他文件