Search code examples
dockergoogle-cloud-platformcontainersgoogle-cloud-run

Expose Both Ports 8080 and 3000 For Cloud Run Deployment


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.

enter image description here 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!


Solution

  • 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.