Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When I try to deploy to Google Cloud Run it fails after some investigation I saw this line in .next/standalone/server.js ```javascript const hostname = process.env.HOSTNAME || 'localhost' ``` This some how make this log when i run docker ```shell - ready started server on 172.17.0.2:3000, url: http://172.17.0.2:3000 ``` I don't know why it's logging this address even if the server running on localhost. So this my fix Set hostname to 0.0.0.0 to avoid deployment failing on Google cloud run.
- Loading branch information
b7eb6d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this fix work for you to force the app to run on localhost ?
b7eb6d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just came here to say that something's recently changed (either Docker, NextJS or recent revisions of Node 18) because this started happening to us as well. After some dependency updates, Cloud Run's startup probe would keep failing and the service would be unavailable until we overrode the
HOSTNAME
variable. Cloud Run requires apps to listen on 0.0.0.0 because 127.0.0.1 refers to the loopback interface which is not available from outside the container. I believe that Docker sets theHOSTNAME
variable to match that. I noticed in the logs that Next used to listen onhttp://localhost:$PORT
according to the logs and then at some point that changed tohttp://127.0.0.1:$PORT
which is when I found this thread after some poking around.b7eb6d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I was trying
localhost
, but only this fixed. Proposing to change here as well.b7eb6d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went in to same problem in Docker Swarm cluster with Traefik proxy. Fixed issue based on this commit. Thanks.