Docker Image On Google Cloud Crashing After about 10 minutes

When I deploy my docker container to cloud run it will run for about 10 minutes and then it crashes.

I was wondering why it is doing this I have set a port so it seems like it should work. Is my Docker file incorrect.

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

# For more information, please refer to https://aka.ms/vscode-docker-python

FROM python:3.8-slim

# Keeps Python from generating .pyc files in the container

ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging

ENV PYTHONUNBUFFERED=1

# Install pip requirements

COPY requirements.txt .

RUN python -m pip install -r requirements.txt

WORKDIR /app

COPY . /app

# Creates a non-root user with an explicit UID and adds permission to access the /app folder

# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers

RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app

USER appuser


CMD ["python", "app.py"] "

I realise I was only adding port mappings to containers not to the images. But I tried exposing one and I got the same result, I’m sure I am making a mistake in my docker file in regards to how I’m exposing the ports.

# For more information, please refer to https://aka.ms/vscode-docker-python

FROM python:3.8-slim

# Keeps Python from generating .pyc files in the container

ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging

ENV PYTHONUNBUFFERED=1

# Install pip requirements

COPY requirements.txt .

RUN python -m pip install -r requirements.txt

WORKDIR /app

COPY . /app

EXPOSE 3000/tcp

# Creates a non-root user with an explicit UID and adds permission to access the /app folder

# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers

RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app

USER appuser



CMD ["python", "app.py"]

Please use the </> to format code (or read about using Markdown). I’ve done that for you now. Also, I removed the almost-duplicate post about the same problem. Please note the pencil icon to edit your own posts if nobody answered yet. Success!

Hi, checked this?

Check if your container is listening for requests on the expected port as documented in the container runtime contract. Your container must listen for incoming requests on the port that is defined by Cloud Run and provided in the PORT environment variable. See Configuring containers for instructions on how to specify the port.

Check if your container is listening on all network interfaces, commonly denoted as 0.0.0.0.

Hi, what I find confusing about cloud run is that you have to upload the images and it builds the containers for you there. You can’t upload a container which has the port assigned.

My understanding was that

EXPOSE 3000/tcp would allow my image to build the correct container within the cloud as long as you set the container of the VM to 3000. And it does run successfully - it just then crashes after 4 or 5 minutes. 

I have tried a few different ways to make sure the ports are being listed to but I'm not sure how to set or check the same way I can with a standard container that I have built on my desktop.


FROM python:3.8-slim

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app

EXPOSE 8080
ENV PORT 8080
ENV HOST 0.0.0.0

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser


# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "app.py"]
type or paste code here
````Preformatted text`

Should this Docker file not allow the image to listen to port 8080?