简体   繁体   English

React Flask 应用程序可在 Docker 容器中运行,但在部署到 Cloud Run 时返回 404 错误

[英]React Flask app works in Docker container but returns 404 error when deployed to Cloud Run

I am at a loss for what the problem is when deploying my app to Google Cloud.将我的应用程序部署到 Google Cloud 时,我不知道问题出在哪里。 Here I run the Docker container on my own system:这里我在自己的系统上运行 Docker 容器:

$ docker run 829c6a550061
[2020-09-01 15:08:37 +0000] [6] [INFO] Starting gunicorn 20.0.4
[2020-09-01 15:08:37 +0000] [6] [INFO] Listening at: http://0.0.0.0:8080 (6)
[2020-09-01 15:08:37 +0000] [6] [INFO] Using worker: threads
[2020-09-01 15:08:37 +0000] [8] [INFO] Booting worker with pid: 8

when I click on the 'http://0.0.0.0:8080' it successfully launches the site.当我单击“http://0.0.0.0:8080”时,它成功启动了该站点。 When I deploy to Cloud Run it gives a URL at the end and says "serving 100% traffic at such and such URL" but when I click on the URL it is a 404 error.当我部署到 Cloud Run 时,它会在最后给出一个 URL 并说“在某某 URL 上提供 100% 的流量”,但是当我点击该 URL 时,它是一个 404 错误。 Cloud Run says that by default the app listens on 8080. Am I missing something? Cloud Run 说默认情况下应用程序侦听 8080。我错过了什么吗? Below is my Dockerfile and I attached a screenshot of Cloud Run's logs.下面是我的 Dockerfile,我附上了 Cloud Run 日志的屏幕截图。

FROM node:13.12.0-alpine as react-build
WORKDIR /ChessKingsCouncil/react_frontend
RUN mkdir public src
COPY ./react_frontend/public ./public
COPY ./react_frontend/src ./src
COPY ./react_frontend/package.json ./
COPY ./react_frontend/package-lock.json ./
RUN npm install
RUN npm run-script build


FROM python:3.8.2
WORKDIR /ChessKingsCouncil/python_backend
ENV PYTHONPATH "${PYTHONPATH}:/app"
RUN pip install Flask
RUN pip install firebase-admin
RUN pip install gunicorn
RUN pip install termcolor
COPY ./python_backend ./
RUN mkdir build
COPY --from=react-build /ChessKingsCouncil/react_frontend/build ./build
ENV PORT 8080
CMD gunicorn --bind :$PORT --workers 1 --threads 8 app:app

Cloud Run deploy logs here Cloud Run 在此处部署日志

It seems you run '$ docker run 829c6a550061' it is a pure docker command.看来你运行 '$ docker run 829c6a550061' 它是一个纯 docker 命令。 However you deploy to Cloud Run which may observe different behavior.但是,您部署到 Cloud Run 时可能会观察到不同的行为。 Before you deploy to the Cloud Run, I recommend you to test the container image locally .在部署到 Cloud Run 之前,我建议您在本地测试容器映像 Also, it seems the Web server has not been installed.此外,似乎还没有安装 Web 服务器。 Nginx should be installed as a web server to respond to HTTP requests.应将 Nginx 安装为 Web 服务器以响应 HTTP 请求。 You can follow this documentation for the Nginx configuration.您可以按照此文档进行 Nginx 配置。

please note that by default the container listens to 0.0.0.0:8080, however, the documentation testing command access port is 9090, container port configuration is required before run the local testing command.请注意,容器默认监听0.0.0.0:8080,但是文档测试命令访问端口是9090,运行本地测试命令之前需要配置容器端口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM