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!
Here is an example of how to expose a port in Dockerfile: The above line will instruct Docker that the container's service can be connected to via port 8080. You can also expose multiple ports: By default, the EXPOSE keyword specifies that the port listens on TCP protocol.
Cloud Run recently added support for changing the default port. You can try "gcloud alpha run deploy ... --port=" or via the Cloud Console UI to deploy.
You cannot do this via Docker, but you can access the container's un-exposed port from the host machine.
You can use all gRPC types, streaming or unary, with Cloud Run. Possible use cases include: Communication between internal microservices. High loads of data (gRPC uses protocol buffers, which are up to seven times faster than REST calls).
The container must listen for requests on 0.0.0.0 on the port defined by the PORT environment variable. In Cloud Run container instances, the PORT environment variable is always set to 8080, but for portability reasons, your code should not hardcode this value.
You can try "gcloud alpha run deploy ... --port=" or via the Cloud Console UI to deploy. Show activity on this post. The PORT environment variable tells you which port your server must listen on internally, the 8080 value is just an example.
You're most likely missing firewall rules to allow incoming traffic to port 8080 on your instances in the project where it is not working, whereas the other project has these rules configured. Google Compute Engine firewall by default blocks all ingress traffic (i.e. incoming network traffic) to your Virtual Machines.
In this method, while creating a container, all you have to do is use the --expose option (as many times as needed) with the port number and optionally the protocol with a /. Here's one example:- docker container run \ --expose 80 \ --expose 90 \ --expose 70/udp \ -d --name port-expose busybox:latest sleep 1d
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With