I am very new to cloud run. I created a very simple express server as shown below with no Dockerfile
as I decided to deploy from source.
import dotenv from 'dotenv';
dotenv.config();
import express from 'express';
const app = express();
const port = process.env.PORT || 8000;
app.get('/test', (req, res) => {
return res.json({ message: 'test' });
})
app.listen(port, async function () {
console.log(`Sample Service running on port ${port} in ${process.env.NODE_ENV} mode`);
});
Please note that I am deploying from source, hence no Dockerfile
in my directory.
Here is the command I used to deploy
gcloud run deploy --source .
And then the error I keep getting back is:
The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
I have no idea where PORT 8080
is coming from as I am listening on PORT 8000
and not 8080.
How can this be resolved?
Thanks
CodePudding user response:
The issue most likely is not to do with the port but with some other problem that is causing the container to fail at startup. I suggest the following:
- Visit Cloud Run in the Google cloud console and for this specific service, go to the logs from the Cloud Run service detail itself. It should tell you the exact reason while the container startup is failing. At times, it could be a dependency, a missing command, etc.
For the port 8080 being used, instead of 8000 -- Cloud Run injects a default port which is 8080. Check out the container contract documentation. You can override that by specifying the --port
parameter in the gcloud command but it may not be necessary at this point.