Zain Khan
Zain Khan

Reputation: 1814

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

Upvotes: 4

Views: 11074

Answers (2)

Lindsay-Needs-Sleep
Lindsay-Needs-Sleep

Reputation: 1441

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.)

Upvotes: 0

Zain Khan
Zain Khan

Reputation: 1814

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

Upvotes: 5

Related Questions