title: How to resolve "container failed to start error" while deploying a docker image to cloud run
body: <p>Problem statement: I have created a docker application ( a simple python code) and trying to deploy and automate run using Google Cloudrun but each time during deployment I see the below error :</p>
  
  <p>command:</p>
  
  <pre><code>gcloud run deploy my_service_name --image gcr.io/project-id/image_name
  </code></pre>
  
  <p>Error</p>
  
  <pre><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 info
  rmation.                                                                                                                                                                                                   
    X Creating Revision... 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 inform
    ation.                                                                                                                                                                                                   
    . Routing traffic...                                                                                                                                                                                     
  Deployment failed            
  
  </code></pre>
  
  <p>My Dockerfile </p>
  
  <pre><code>#FROM python:3.8
  FROM python:latest
  # Copy application dependency manifests to the container image.
  COPY requirements.txt ./
  # Install production dependencies.
  RUN pip install -r requirements.txt
  # Copy main 
  COPY main.py ./
  ENV PORT = 8080
  CMD [ "python", "./main.py" ]
  </code></pre>
  
  <p>There is nothing fancy in my python program just running a bunch of sql queries and updating the BQ table. </p>
  
  <p>I have used the <a href="https://cloud.google.com/run/docs/troubleshooting" rel="nofollow noreferrer">troubleshooting steps</a> listed by Google and the container runs on my local without any issue.</p>
  
  <p>Can someone please guide me as to where am I going wrong ? </p>
  
  <p><strong>Edit:</strong> Updated the Dockerfile to ENV PORT=8080 (removed the space). Still receiving the same error . deployment Logs below </p>
  
  <pre><code>Deployment failed                                                                                                                                                                                          
  DEBUG: (gcloud.run.deploy) 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.
  Traceback (most recent call last):
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 983, in Execute
      resources = calliope_command.Run(cli=self, args=args)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 807, in Run
      resources = command_instance.Run(args)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/surface/run/deploy.py", line 258, in Run
      build_log_url=build_log_url)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 1087, in ReleaseService
      self.WaitForCondition(poller)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 594, in WaitForCondition
      return waiter.PollUntilDone(poller, None, wait_ceiling_ms=1000)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 326, in PollUntilDone
      sleep_ms=sleep_ms)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 219, in RetryOnResult
      result = func(*args, **kwargs)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 251, in Poll
      self._PollTerminalSubconditions(conditions, conditions_message)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 230, in _PollTerminalSubconditions
      self._PossiblyFailStage(condition, message)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 349, in _PossiblyFailStage
      message)
    File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 915, in FailStage
      raise failure_exception  # pylint: disable=raising-bad-type
  DeploymentFailedError: 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.
  ERROR: (gcloud.run.deploy) 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></pre>
  
  <p>Logs below: </p>
  
  <pre><code>{
   insertId: "5ec6519000ca44b34efd"  
   labels: {
    instanceId: "00bf4bf02dd520b9906e825b7333299aac62e9e4f12e4090ccd3b3bfd2435203c13fbe3c09193bd6dd408286adf939dff830"   
   }
   logName: "projects/project-name/logs/run.googleapis.com%2Fvarlog%2Fsystem"  
   receiveTimestamp: "2020-05-18T10:46:09.076605834Z"  
   resource: {
    labels: {
     configuration_name: "measurement-protocol-hit"    
     location: "us-central1"    
     project_id: "project-id"    
     revision_name: "measurement-protocol-hit-00001-det"    
     service_name: "measurement-protocol-hit"    
    }
    type: "cloud_run_revision"   
   }
   severity: "WARNING"  
   textPayload: "Container called exit(0)."  
   timestamp: "2020-05-18T10:36:09.068639979Z"  
  }
  </code></pre>