Search code examples
pythongoogle-app-enginegoogle-cloud-platformdockerfilerasa

How to install pip packages with Dockerfile? Getting permission restrictions error


I have the following Dockerfile that I use to deploy an Rasa Bot app on Google's App Engine:

FROM rasa/rasa
ENV BOT_ENV=development
COPY . /var/www
WORKDIR /var/www
RUN pip install rasa phonenumbers pgeocode
#ENTRYPOINT ["rasa", "run", "-vv", "--enable-api", "actions"]
ENTRYPOINT ["rasa", "run", "-vv", "--enable-api", "--endpoints", "endpoints.yml", "--credentials", "credentials.yml", "-p", "8080"]

But the deployment fails to install the phonenumbers and pgeocode packages, somehow doesn't have problem with rasa.

The error I get is this:

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/build/lib/python3.6/site-packages/phonenumbers'
Consider using the `--user` option or check the permissions.

The command '/bin/sh -c pip install rasa phonenumbers pgeocode' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

I have tried using the --user as suggested, and in some other questions I saw answers suggesting using sudo with -H flag, but that as well fails, with a different error saying that sudo is not recognized.

If I remove those 2 failing packages, my app runs, except that it can't perform some actions for which those packages are needed.

Any idea how I can solve this?

Thanks!


Solution

  • You're using the rasa/rasa base image, this is why rasa is either already installed or installs successfully.

    The documentation for this image suggests using the --no-cache-dir flag:

    RUN pip install --no-cache-dir jupyter
    

    You can also try running your Dockerfile commands as the root user by doing:

    FROM rasa/rasa
    USER root