question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pipenv virtualenv in Docker not working on Google Cloud Run in gVisor sandbox

See original GitHub issue

Issue 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

5reactions
jonahbentoncommented, Apr 16, 2020

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.

1reaction
hedclercommented, Sep 17, 2020

@sjosegarcia Uncomment and fix the line #ENV PIPENV_VENV_IN_PROJECT=1 on your Dockerfile to ENV PIPENV_VENV_IN_PROJECT 1 and try to use pipenv run alembic upgrade head and pipenv run python /app/bin/web.py on your startup.sh file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker image deploys locally but fails on Google Cloud Run
This is one solution to the problem - set virtualenvs.in-project true # Create virtualenv at .venv in the project instead of ~/.cache/ RUN ......
Read more >
Cannot run python containers on Google Cloud Build
The container works outside Google cloud build just fine (verified by pulling the exact container built locally and running it).
Read more >
Quellcode-Pakete in »sid«, Unterbereich misc
... google-android-m2repository-installer (41+r1) [contrib]; google-android-sdk-docs-installer (24+r3) [contrib]; google-api-client-java (1.27.1-2) ...
Read more >
Compare Packages Between Distributions - DistroWatch.com
NixOS unstable, Bodhi Linux 7.0.0-alpha3. 0ad-0.0.26 0ad-data-0.0.26 0verkill-unstable-2011-01-13 0xtools-1.1.3 0x-unstable-2022-07-11 1am-20141106-git
Read more >
Homebrew Analytics Formula Install Events (365 days)
#223, docker-compose, 12,056, 0.07% ... #677, astronomer/cloud/astrocloud@1.5.0-stage, 1,147, 0.01% ... #1154, knative-sandbox/kn-plugins/quickstart ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found