Cloud Run: "Failed to start and then listen on the port defined by the PORT environment variable." When I use 8080
Feb 9
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:
1 answer
Accepted answer · original discussion
Aug 13
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/amd64flag 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.
3 question comments
Use comments to ask for clarification. Post a solution as an answer.
Feb 9
Aug 5