I know there are many posts about this, but I still can’t resolve this. It’s a .Net Core 3.1 app using React.
npm run build
completes successfully.
I have PORT=8080
in my .env file
I have configured my service to run on port 8080.
I have my Dockerfile set to expose 8080:
but I still get the following:
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’ve checked the logs, but it just shows the same message with a link to itself:
So the logs seem useless.
I am deploying as follows:
docker build -f foobarDataViz.UIDockerfile --force-rm -t foobardataviz.ui . --no-cache
This builds successfully.docker run -d -p 8080:80 --name foobar foobardataviz.ui
This runs successfully and I can browse locally on port 8080docker push us-central1-docker.pkg.dev/foobar-poc/foobar/foobardataviz.ui:latest
- I then go to Cloud Run and click "Edit and Deploy New Revision", which does some processing for a little while, but fails with the above error
So, the error suggests it’s not exposing the port, or it’s just failing to start altogether. Could it be that my docker image is not compatible with how I’ve set up Cloud Run?
Thanks in advance
2
Answers
your #2: your port is served on the 80 in your container, and exposed as 8080 on your local machine. You have your issue here.
Use the port 80 when you configure your Cloud Run service. This port must be listen by Cloud Run, not the 8080 that is not listen by your container. However, I’m not sure it will work.
If you look for a .NET solution about the configuration, I absolutely don’t know .NET framework.
EDIT 1
If you perform that command
That means you forward the internal port 80 outside Docker and expose it on the 8080. That’s why you can test your app locally on the 8080 port.
With Cloud Run, you have a similar configuration: you can set the port to listen inside your container. (Take your 1st screenshot, it’s the 4th line). You can change that when you deploy your Cloud Run service
Try to put the 80 port (I say try because sometimes the port 80 requires additional privilege).
Now, why your .NET app exposes the port 80 and not the port 8080, as I said, I absolutely don’t know!
The port that your dotnet container is listening on (default) is set in propertieslaunchsettings.json. The default configuration look like this:
Note: The Cloud Run instance (container) should not listen on HTTPS. The Cloud Run GFE forwards traffic using HTTP.
Modify propertieslaunchsettings.json as follows to use the default port which is 8080:
A better solution is to modify CreateHostBuilder() to read the port from the environment.