title: I cannot resolve "Failed to start and then listen on the port defined by the PORT environment variable." error in Google Cloud Run with a Docker image
body: <p>I know there are <a href="https://stackoverflow.com/questions/57945278/why-cloud-run-showing-listen-on-this-port-error">many</a> <a href="https://stackoverflow.com/questions/61834613/how-to-resolve-container-failed-to-start-error-while-deploying-a-docker-image">posts</a> <a href="https://stackoverflow.com/questions/59524020/cloud-run-error-container-failed-to-start">about</a> <a href="https://stackoverflow.com/questions/66127933/cloud-run-failed-to-start-and-then-listen-on-the-port-defined-by-the-port-envi">this</a>, but I still can't resolve this. It's a .Net Core 3.1 app using React.</p>
  <p><code>npm run build</code> completes successfully.</p>
  <p>I have <code>PORT=8080</code> in my .env file</p>
  <p>I have configured my service to run on port 8080.
  <a href="https://i.stack.imgur.com/mvL8k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mvL8k.png" alt="enter image description here" /></a></p>
  <p>I have my Dockerfile set to expose 8080:</p>
  <p><a href="https://i.stack.imgur.com/GhFtV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GhFtV.png" alt="enter image description here" /></a></p>
  <p>but I still get the following:
  <code>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.</code></p>
  <p>I've checked the logs, but it just shows the same message with a link to itself:
  <a href="https://i.stack.imgur.com/k7E44.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k7E44.png" alt="enter image description here" /></a></p>
  <p>So the logs seem useless.</p>
  <p>I am deploying as follows:</p>
  <ol>
  <li><code>docker build -f foobarDataViz.UI\Dockerfile --force-rm -t foobardataviz.ui . --no-cache</code>
  This builds successfully.</li>
  <li><code>docker run -d -p 8080:80 --name foobar foobardataviz.ui</code>  This runs successfully and I can browse locally on port 8080</li>
  <li><code>docker push us-central1-docker.pkg.dev/foobar-poc/foobar/foobardataviz.ui:latest</code></li>
  <li>I then go to Cloud Run and click &quot;Edit and Deploy New Revision&quot;, which does some processing for a little while, but fails with the above error</li>
  </ol>
  <p>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?</p>
  <p>Thanks in advance</p>