skip to Main Content

I’m unable to install the package inside my docker container, please let me know how can I solve this.

Warning:

WARNING: The directory ‘/home/app/.cache/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo’s -H flag.

error:

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/home/app'
Check the permissions.

Dockerfile:

FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app
EXPOSE 8000

COPY ./core/ /app/
COPY ./scripts /scripts

RUN pip install --upgrade pip
COPY requirements.txt /app/
RUN pip install -r requirements.txt && 
    adduser --disabled-password --no-create-home app && 
    mkdir -p /vol/web/static && 
    mkdir -p /vol/web/media && 
    chown -R app:app /vol && 
    chmod -R 755 /vol && 
    chmod -R +x /scripts

USER app

CMD ["/scripts/run.sh"]

command inside container:

pip install django-storages

2

Answers


  1. Chosen as BEST ANSWER

    In my case, I've installed the package using the root user by adding -u 0 which tells docker to go in as root user.

    docker exec -u 0 -it mycontainer bash
    

  2. Your user’s '/home/app' directory either doesn’t exist or has the wrong permissions.

    It looks like you are passing --no-create-home to adduser, that’s probably your issue.

    (For others who find their way here, to create my user I was using RUN useradd -u 1000 app but my home directory was not being created for some reason… Using RUN adduser --uid 1000 --disabled-password app worked for me instead.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search