2
votes

I got this error message when I try to run my container in Google Cloud Run.

type: Ready
status: 'False'
reason: HealthCheckContainerError
message: |-
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 already checked the followings but nothing helped to me:

My container is running locally and it's listening on default PORT 8080 with HOST configured as 0.0.0.0.

My Dockerfile:

FROM node:10

WORKDIR /usr/src/app

ENV PORT 8080
ENV HOST 0.0.0.0

COPY package*.json ./

RUN npm install --only=production

COPY . .

RUN npm run build

CMD npm start

Any idea on why Cloud Run keeps failing to listen on the port?


Project GitHub repo:

https://github.com/fodorpapbalazsdev/ssr-app

4
Edit your question with all details. Links change, break and get deleted. The content of links might change in the future. It is OK to include links as an addition reference but you must include everything in the question.John Hanley
What's your logs in Cloud Logging?guillaume blaquiere
@guillaumeblaquiere see my first comment here: github.com/fodorpapbalazsdev/ssr-app/issues/1Balázs Fodor-Pap
Did you manage to find a solution for this problem? I'm facing the same problem and would appreciate any help!raphael_mav
@BalázsFodor-Pap Have you fixed it yet? If anyone has answered your question please accept the answer.JM Gelilio

4 Answers

4
votes

Just to check, are you using the M1 Macbook? I found a solution for myself after facing this issue for some time, might not be the solution for you but just to share some insights I found for other MacBook users.

tl;dr

build your Docker container with the --platform linux/amd64 flag before deploying the image to Cloud Run

========================================================

Long story:

Aside from the container failed to start and listen to the $PORT error, my logs were showing the following: Application failed to start: Failed to create init process: failed to load /usr/local/bin/npm: exec format error. Upon some digging, one of the reasons this happens is that we are trying to run an arm64 image (built on M1 MacBook) on a different host platform.

GCP does mention on this page here that Executables in the container image must be compiled for Linux 64-bit. Cloud Run specifically supports the Linux x86_64 ABI format.

I guess that explains why building the image on Cloud Build works from the other answer in this post.

0
votes

The attached logs seem to indicate your entrypoint may be malformed.

Failed to create init process: failed to load /usr/local/bin/docker-entrypoint.sh: exec format error",

Are there any commands or arguments specified as input? Would it be possible for you to put the complete yaml for the cloud run instance either in your repo, a gist, or in this question?

Cloud Console

0
votes

You've only configured an environment variable on your Dockerfile but your program is not using it. By default, your app is still looking at localhost:3000.

To fix this, go to your nuxt.config.js and add the server config like this:

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  server: {
    port: process.env.PORT, // default: 3000
    host: process.env.HOST  // default: localhost
  },
  head: {
    title: 'ssr-app',
    htmlAttrs: {
      lang: 'en'
    },

    ...
}

Afterwards, rebuild the container and redeploy a new revision to Cloud Run.

0
votes

As you can see in Dockerfile for node:10 official image https://github.com/nodejs/docker-node/blob/4ab6ab7d06845aa950054ec5522fe8b81927bf05/10/alpine3.10/Dockerfile they don't expose any port. As long as you are not changing anything to ENTRYPOINT I would suspect you add EXPOSE 8080 to your Dockerfile and it should do the work.

FROM node:10

WORKDIR /usr/src/app

ENV PORT 8080
ENV HOST 0.0.0.0

COPY package*.json ./

RUN npm install --only=production

COPY . .

RUN npm run build
EXPOSE 8080
CMD npm start

UPDATE

As the issue seems rather strange I went an extra mile and quickly set up copy of your repo with the build pipeline and everything work just fine. Here you can access your app https://testssr-6dl3hr2riq-uc.a.run.app/

Dockerfile

FROM node:10

WORKDIR /usr/src/app

ENV PORT 8080
ENV HOST 0.0.0.0

COPY package*.json ./

RUN npm install 

COPY . .

RUN npm run build

CMD npm start

cloudbuild.yaml

steps:
- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: ['-c','docker build --no-cache -t gcr.io/$PROJECT_ID/testssr:$SHORT_SHA .']
- name: 'gcr.io/cloud-builders/docker'
  args: ['push','gcr.io/$PROJECT_ID/testssr:$SHORT_SHA']
- name: 'gcr.io/cloud-builders/gcloud'
  args:
    - 'beta'
    - 'run'
    - 'deploy'
    - 'testssr'
    - '--image=gcr.io/$PROJECT_ID/testssr:$SHORT_SHA'
    - '--region=us-central1'
    - '--platform=managed'