1

I have been running a cloud build service which deploys a nextjs application to a cloud run container for a year now. This week, after making some commits, I was unable to successfully deploy the changes even though I have not changed anything on GCP. On cloud build, the error reads:

"Deploy": ERROR: (gcloud.run.services.update) Cloud Run error: The user-provided container failed to start and listen on the port defined provided by the PORT=3000 environment variable. Logs for this revision might contain more information.

after it downloads this image

ERROR: build step 2 "gcr.io/google.com/cloudsdktool/cloud-sdk:slim" failed: step exited with non-zero status: 1

My steps on my cloudbuild.yaml file have been:

  1. download .env file

  2. build the container image

  3. push the container image to gcr

  4. deploy container image to Cloud Run Anthos

I have even increased my timeout to 900s because that is the first error that I received. These steps have successfully deployed the application in the past and I have only changed the timeout time in cloudbuild.yaml

My dockerfile only has the following:

FROM node:14-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN npm rebuild node-sass
RUN npm run build
EXPOSE 3000
CMD ["npm","start"]
David Maze
  • 130,717
  • 29
  • 175
  • 215

3 Answers3

1

This is a very generic error that GCP throws. I've ran into the same one just the other day and it had nothing to do with the port itself.

In my case, I happened to forget to create a directory before changing the permission in the Dockerfile.

Try to check under the "Logs" tab. There you can usually find better information about the cause. GCP Logs

0

Try running this on port 8080 instead of 3000

0

The issue most likely is that you do not allow your Dockerfile to use $PORT environment variable anywhere - customize your CMD directive to include $PORT so that your container might accept it from Cloud Run environment and start the app on that port. The idea is that Cloud Run passes this environment variable and your container must accept it - a container will not be able to start on Cloud Run otherwise (it says so in the docs).

vadim_v
  • 73
  • 2
  • 9