Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

My python file worked and run well in container but got error contianer failed to listen to PORT

I have my python file .py to run in docker. It works well in local but when I put it to Cloud Run. Only the function worked well but got the error

Cloud Run error: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information. Logs URL: .....

I have searched a lot, try to follow the container runtime contract but I don't know much about setting port.

My Dockerfile:

FROM python:3.10
RUN apt-get update
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libnss3 lsb-release xdg-utils wget
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
EXPOSE 80
CMD ["python", "-u", "app.py"]

 Several ways I have tried:

  • set EXPOSE 8080 
  • set ENV PORT 8080 and ENV HOST 0.0.0.0
  • both of the former setting together

Actually, when my first run didn't expose or set any environment variables but also didn't work.

Btw, I'm new to the forums and not sure which forum needed for the GCP products

0 1 591
1 REPLY 1

osvaldolopez
Former Googler

To configure the port, you can check this similar case in Stackoverflow and also this troubleshooting from the official Cloud Run documentation. If that doesn’t work, you should then attempt to troubleshoot Cloud Run service using Stackdriver tools for more in-depth investigation as seen here.

You can get more public support here:

  1. Cloud Run Support.
  2. Known Issues for Cloud Run.
  3. Troubleshoot Cloud Run issues.
  4. Stackoverflow using google-cloud-run tag.