I'm trying to deploy a service to Google Cloud Runusin using commandline. But it is failing with error below.
X Deploying... Revision 'XXXXXXXXX' is not ready and cannot serve traffic. The service has encountered an error during container import. Please try again later. Resource readiness deadline exceeded.
X Creating Revision... The service has encountered an error during container import. Please try again later. Resource readiness deadline exceeded.
. Routing traffic...
✓ Setting IAM Policy...
Deployment failed
ERROR: (gcloud.run.deploy) The service has encountered an error during container import. Please try again later. Resource readiness deadline exceeded.
Below is the command I have used.
gcloud run deploy my-service --quiet --platform managed --allow-unauthenticated --region asia-southeast1 --image docker.io/<username>/<imgname> --project <projectid> --memory 1548M --concurrency 1 --platform managed
My SDK version
Google Cloud SDK 420.0.0
beta 2023.02.24
bq 2.0.86
bundled-python3-unix 3.9.16
core 2023.02.24
gcloud-crc32c 1.0.0
gsutil 5.20
My dockerfile is as below.
FROM python:3.9-bullseye
ENV PYTHONUNBUFFERED True
ENV APP_HOME /app
ENV TF_CPP_MIN_LOG_LEVEL "3"
WORKDIR $APP_HOME
COPY . ./
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y ffmpeg libsm6 libxext6 libgl1 python3-opencv libgl1-mesa-glx
RUN pip install --no-cache-dir -r requirements.txt
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
Also built image is working fine on local docker engine. output
My docker hub image size and details are as below
COMPRESSED SIZE - 3.54 GB
OS/ARCH - linux/amd64
Solved!
Awesome news, I managed to fix my issue! The problem was that my Docker image was too big, about 5GB in size. So, I decided to optimize my Dockerfile and remove any unnecessary files, dependencies, and layers to shrink the size down to 1.9GB. After doing so, I was able to deploy my application without any errors.
It's important to keep in mind that large Docker images can cause problems during cloud run deployment, so it's always a good idea to optimize them.