themrdan
themrdan

Reputation: 117

Deploying flask app to Cloud Run with Pytorch

I am trying to deploy a Flask app to cloud run using the cloud shell editor. I am getting the following error:

Failed to build the app. Error: unable to stream build output: The command '/bin/sh -c pip3 install torch==1.8.0' returned a non-zero code: 1

This is the docker file I am using:

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip3 install torch==1.8.0
RUN pip3 install sentence-transformers==2.0.0
RUN pip3 install ultimate-sitemap-parser==0.5
RUN pip3 install Flask-Cors==3.0.10
RUN pip3 install firebase-admin
RUN pip3 install waitress==2.0.0
RUN pip3 install Flask gunicorn

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

This is my first time deploying to cloud run and I am very inexperienced using Docker. Can you give me any suggestions of what I might be doing wrong?

Upvotes: 0

Views: 349

Answers (2)

slbinilkumar
slbinilkumar

Reputation: 1

Issue is with your torch installation. Check all the requirements for torch is mentioned in your docker file.Or go with a stable version of torch.

Upvotes: 0

themrdan
themrdan

Reputation: 117

I fixed this by changing:

FROM python:3.9-slim

To

FROM python:3.8

Upvotes: 1

Related Questions