1
votes

Container Contract says, cloud run should listen to the port defined by PORT environment variable. The environment variable is set to 8080. My question is can we change this variable to different port?

link

5

5 Answers

4
votes

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.

4
votes

If you build your container with a Dockerfile, you can specify the PORT environment variable with

ENV PORT {Number}

Here's an example Dockerfile:

WORKDIR /app
COPY . .

RUN npm install

RUN npm run build

ENV PORT 443

CMD ["node", "server.js"]

Hope this helps!

3
votes

From Documentation:

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.

Your existing applications must listen on PORT environment variable to work on Cloud Run, as specified on the documentation.

0
votes

it not because the port, it error on npm script on server enter image description here

I got the same "Missing Port" error. You can find the logs when you click on the cloud run service.

-1
votes

The PORT environment variable tells you which port your server must listen on internally, the 8080 value is just an example. You cannot change it yourself. This is unrelated to the port visible from the outside that your clients connect to.