Reputation: 1996
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
Upvotes: 1
Views: 8934
Reputation: 8806
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:
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.
Upvotes: 5