user5418541
user5418541

Reputation: 61

Google Cloud Run Port

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

Upvotes: 5

Views: 25350

Answers (5)

Hiep Tran
Hiep Tran

Reputation: 4093

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.

Upvotes: -1

McKay M
McKay M

Reputation: 448

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!

Upvotes: 4

wlhee
wlhee

Reputation: 2584

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.

Upvotes: 8

sllopis
sllopis

Reputation: 2368

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.

Upvotes: 5

Jan-Gerd
Jan-Gerd

Reputation: 1289

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.

Upvotes: -2

Related Questions