cloud run error: container failed to start. failed to start and then listen on the port defined by the port environment variable.

In your code, you probably aren't listening for incoming HTTP requests, or you're listening for incoming requests on the wrong port.

As documented in the Cloud Run container runtime contract, your container must listen for incoming HTTP requests on the port that is defined by Cloud Run and provided in the $PORT environment variable.

If your container fails to listen on the expected port, the revision health check will fail, the revision will be in an error state and the traffic will not be routed to it.

For example, in Node.js with Express, you should use :

const port = process.env.PORT || 8080;
app.listen(port, () => {
  console.log('Hello world listening on port', port);
});
In Go:

port := os.Getenv("PORT")
if port == "" {
        port = "8080"
}
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment varia ble Nodejs Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable nodejs Container failed to start. Failed to start and then listen on the port defined by th e PORT environment variable Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable jhipster gcp Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information. Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. nuxt Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable cloud run error: container failed to start. failed to start and then listen on the port defined by the port environment variable.
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source