为 Cloud Run 部署公开 8080 和 3000 端口 [英] Expose Both Ports 8080 and 3000 For Cloud Run Deployment
问题描述
TL:DR - 我正在尝试将我的 MERN 堆栈应用程序部署到 GCP 的 Cloud Run.我认为这是一个端口问题.
我的 React 应用程序位于 client
文件夹中在我的 Node.js 应用程序中.
这是我的一个 Dockerfile
来运行前端和后端:
FROM node:13.12.0-alpine工作目录/app复制 ../# 为be连接器安装组件运行 npm install --silentWORKDIR/应用程序/客户端运行 npm install --silent工作目录/app运行 chmod +x/app/entrypoint.sh入口点 [/app/entrypoint.sh"]
...这是我的 entrypoint.sh
文件:
#!/bin/sh节点/app/index.js &cd/应用程序/客户端npm 开始
docker-compose up
在本地工作,docker run -p 8080:8080 -p 3000:3000
运行我构建的镜像.端口 8080 用于 Node,端口 3000 用于 React 应用程序.但是,在 Cloud Run 上,该应用程序无法运行.当我访问部署到 Cloud Run 的应用时,前端最初会加载一瞬间,但随后应用在尝试向 API 发出请求时崩溃.
在高级设置中,有一个默认为 8080 的容器端口.我尝试将其更改为 3000,但都不起作用.我无法输入 8080,3000,因为该字段仅对端口采用有效整数.是否可以像这样同时将 React + Node 部署到 Cloud Run?如何让 Cloud Run 在 8080 和 3000 上同时收听,而不是 2 个中的一个?
谢谢!
目前不可以.
相反,您可以在 Cloud Run 中运行多个进程,而是使用 nginx 根据 URL 代理它们之间的请求,类似于 this answer 中的建议.p>
TL:DR - I am trying to deploy my MERN stack application to GCP's Cloud Run. Struggling with what I believe is a port issue.
My React application is in a client
folder inside of my Node.js application.
Here is my one Dockerfile
to run both the front-end and back-end:
FROM node:13.12.0-alpine
WORKDIR /app
COPY . ./
# Installing components for be connector
RUN npm install --silent
WORKDIR /app/client
RUN npm install --silent
WORKDIR /app
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT [ "/app/entrypoint.sh" ]
... and here is my entrypoint.sh
file:
#!/bin/sh
node /app/index.js &
cd /app/client
npm start
docker-compose up
works locally, and docker run -p 8080:8080 -p 3000:3000 <image_id>
runs the image I built. Port 8080 is for Node and port 3000 for the React app. However, on Cloud Run, the app does not work. When I visit the app deployed to Cloud Run, the frontend initially loads for a split second, but then the app crashes as it attempts to make requests to the API.
In the Advanced Settings, there is a container port which defaults to 8080. I've tried changing this to 3000, but neither works. I cannot enter 8080,3000, as the field takes valid integers only for the port. Is it possible to deploy React + Node at the same time to Cloud Run like this? How can I have Cloud Run listen on both 8080 and 3000, as opposed to just 1 of the 2?
Thanks!
It's not currently possible.
Instead, you can run multiple processes inside Cloud Run, but instead use nginx to proxy requests between them depending on the URL, similar to what's recommended in this answer.
这篇关于为 Cloud Run 部署公开 8080 和 3000 端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!