Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Denied When Installing Packages Using Pip In Docker Container Django

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
like image 487
Zain Khan Avatar asked Sep 12 '25 19:09

Zain Khan


1 Answers

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
like image 187
Zain Khan Avatar answered Sep 15 '25 09:09

Zain Khan