Sean D
Sean D

Reputation: 4292

(gcloud.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port

After successfully deploying a container using gcloud builds submit --tag gcr.io/projectname/testserver and then attempting to run gcloud run deploy --image gcr.io/projectname/testserver --platform managed I see this error:

$ gcloud run deploy --image gcr.io/projectname/testserver --platform managed
Please specify a region:
 // options removed

Service name (testserver):  
Allow unauthenticated invocations to [testserver] (y/N)?  y

Deploying container to Cloud Run service [testserver] in project [projectname] region [us-central1]
X Deploying new service... 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 r
evision might contain more information.    
  X Creating Revision... Cloud Run error: C
  ontainer failed to start. Failed to start
   and then listen on the port defined by t
  he PORT environment variable. Logs for th
  is revision might contain more informatio
  n.                                       
  . Routing traffic...                     
  ✓ Setting IAM Policy...                  
Deployment failed                          
ERROR: (gcloud.run.deploy) 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.

I have a very simple project, all in the root folder:

// Dockerfile
FROM node:12-slim

# Create app folder
WORKDIR /usr/src/app

# Install app deps. Copy the lock file
COPY package*.json ./
RUN npm install

COPY . ./
CMD ["node", "testServer.js"]
// testServer.js
const Koa = require("koa");
const koa = new Koa();

koa.get('/', async ctx => {
  ctx.body = "Koa server running"
});

const port = process.env.PORT || 8080;

koa.listen(port);

Anyone know what's causing this? Been trying to solve it since yesterday and now even with this minimal project it seems to be having issues.

Upvotes: 2

Views: 2726

Answers (2)

Marcel
Marcel

Reputation: 3255

Same error here. I solved that increasing the timeout.

Upvotes: 1

Emil Gi
Emil Gi

Reputation: 1168

I received TypeError: app.get is not a function with your code. Looks like this syntax is obsolete. Rewrote with koa-router and worked just fine.

Anyway try to test your code locally with docker run before deploying. And also you can find more precise error messages during deployment in console-> logging-> cloud run revision-> revision_id

Upvotes: 2

Related Questions