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:
https://cloud.google.com/run/docs/troubleshooting
Cloud Run error: Container failed to start
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
Cloud Run is a managed compute platform that enables you to run containers that are invocable via requests or events. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications.
Some Google Cloud services have Google-managed service accounts that allow the services to access your resources. These service accounts are known as service agents. You might see evidence of these service agents in several different places, including a project's allow policy and audit log entries for various services.
Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information. You should check log on Cloud Run, It can't start because something wrong on that 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 revision might contain more information. #1 Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information. You should check log on Cloud Run, It can't start because something wrong on that service. Sorry, something went wrong. What do the Cloud Run logs show? Sorry, something went wrong.
In our case, port 8080 was already being used by another application and hence the web server failed to start. Usually, you would get this error in the case of port 8080, 8081, 9090 etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With