The Docker image / container worked fine on Ubuntu, however I wanted to have access to the static folder. Therefore I added "Host volumes" to the docker-compose.yml (volumes was empty before):
version: '3.3'
services:
api:
build:
context: .
restart: always
ports:
- "8000:8000"
volumes:
- ./app_static:/app/static
$ docker-compose up
After building the image and running the python manage.py collectstatic
command,
I get the following error:
PermissionError: [Errno 13] Permission denied: 'static/media'
The folder structure inside the docker image looks like this:
appuser@1e2bc02404a2:/app$ ls -la
total 24
drwxr-xr-x 1 appuser appuser 4096 Mar 29 21:50 .
drwxr-xr-x 1 root root 4096 Mar 29 21:51 ..
drwxr-xr-x 1 appuser appuser 4096 Mar 29 21:00 api
-rw-r--r-- 1 appuser appuser 765 Mar 29 21:00 manage.py
drwxr-xr-x 1 appuser appuser 4096 Mar 29 21:00 mausefallentest
drwxr-xr-x 2 root root 4096 Mar 29 21:51 static
The problem is, that after adding Host volumes to the docker-compose file, the user for the static folder changed to root. But the Docker image is runnung under the "appuser" user. Thus i get the permission denied error.
But how can i solve this problem ? I only have this problem on my Ubuntu server. On Windows its working fine.
Here the endpart of the Django-Dockerfile:
...
RUN pip install --no-cache-dir -r /scripts/requirements.txt
# Creating Work Directory
WORKDIR /app
RUN useradd appuser
RUN chown -R appuser:appuser /app
RUN chmod -R 777 /app/static
USER appuser
CMD ["sh", "-c", "python manage.py collectstatic --no-input; python manage.py migrate; gunicorn api.wsgi:application --bind 0.0.0.0:8000"]