Reputation: 459
I am using a docker file to handle my django app. I added user to the docker file as following:
FROM python:3.9-alpine3.13
LABEL maintainer="H.Bazai"
ENV PYTHONUNBUFFERED 1
COPY requirements.txt /tmp/
COPY requirements.dev.txt /tmp/
COPY app /app/
WORKDIR /app
EXPOSE 8000
ARG DEV=true
RUN rm -rf /var/cache/apk/*
RUN apk update && \
apk add --no-cache --virtual .build-deps \
build-base postgresql-dev musl-dev zlib-dev jpeg-dev && \
apk add --no-cache postgresql-client postgresql-dev jpeg && \
python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; then \
/py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp/* && \
apk --purge del .build-deps && \
adduser \
--disabled-password \
--no-create-home \
hbazai && \
mkdir -p /vol/web/media && \
mkdir -p /vol/web/static && \
chown -R hbazai:users /vol && \
chmod -R 755 /vol
ENV PATH="/py/bin:$PATH"
USER hbazai
Then I build it. "docker-compose build". Up to here everything is ok.
Then when I use the bellow command to makemigration, I got the error of ' permission denied '.
The command: docker-compose run --rm app sh -c "python manage.py makemigrations"
The Error:
Creating recepie-api-django_app_run ... done
Migrations for 'core':
core/migrations/0005_recipe_image.py
- Add field image to recipe
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/py/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 190, in handle
self.write_migration_files(changes)
File "/py/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 228, in write_migration_files
with open(writer.path, "w", encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: '/app/core/migrations/0005_recipe_image.py'
ERROR: 1
I would appreciate it if somebody can help me out.
I tried many things to give permission to the user of my ubuntu. (chown and chmode) but I still get the error.
Upvotes: 0
Views: 239