pipenv virtualenv in Docker not working on Google Cloud Run in gVisor sandbox
See original GitHub issueIssue description
Docker container with CMD pipenv run ...
fails on Google Cloud Run but runs locally.
As described below, the Dockerfile contains a step RUN pipenv install
. But logs from the cloud run shows that pipenv run
triggers the installation of a new virtualenv.
This is not the case when running the container on my local machine.
Perhaps the issue is to do with the gVisor sandbox used on managed gcloud run. The overview of system compatibilty could hold the key but I have no idea.
Steps to replicate
I have modified the troubleshoot example for Google Cloud Run to use pipenv instead of pip.
So the modification I made is to replace requirement.txt
with Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
pytest = "==4.6.6"
gunicorn = "==20.0.4"
Flask = "==1.1.1"
[requires]
python_version = "3.8"
and Dockerfile
RUN pip install pipenv
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY Pipfile Pipfile.lock ./
RUN pipenv install --deploy --ignore-pipfile
COPY . .
CMD pipenv run gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
building the image and pushing to GCR with PROJECT_ID, then running locally
PORT=8080 && docker run --rm -e $PORT -p 9000:$PORT \
-e NAME="Robust World" \
gcr.io/PROJECT_ID/hello-service
works fine, but creating the cloud run service fails.
The pipenv run
command apparantly doesn’t find the virtualenv, starts creating a new one which doesn’t contain requirement gunicorn
and breaks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9
Top GitHub Comments
Solved by adding to Dockerfile:
ENV PIPENV_VENV_IN_PROJECT 1
from
https://pipenv.pypa.io/en/latest/install/#virtualenv-mapping-caveat
This is probably a Cloud Run bug.
@sjosegarcia Uncomment and fix the line
#ENV PIPENV_VENV_IN_PROJECT=1
on your Dockerfile toENV PIPENV_VENV_IN_PROJECT 1
and try to usepipenv run alembic upgrade head
andpipenv run python /app/bin/web.py
on your startup.sh file.