Docker Community Forums

Share and learn in the Docker community.

Proper Permissions between Nginx and Django/Gunicorn

Hey guys,

I am new to docker but I have a question about the proper way to share named volumes between nginx and Django. I am sorry if this in the wrong forum

I got the below docker compose to work and nginx is serving up the static files, however I had to set the static folder to chmod 777

version: '3.4'

services:
  test_app:
    image: test_app
    build:
      context: .
      dockerfile: test_app/Dockerfile.prod
    expose:
      - 8000
    volumes:
      - static:/app/static
  nginx:
    image: test_app_nginx
    build:
      context: .
      dockerfile: nginx/Dockerfile
    ports:
      - "80:80"
    volumes: 
      - static:/static
    depends_on: 
      - test_app

volumes: 
  static:

My two Dockerfiles
NGINX

Grab base image of nginx

FROM nginx

# Copy files over

RUN rm /etc/nginx/conf.d/default.conf

COPY nginx/test_app.conf /etc/nginx/conf.d

# mkdir nginx logs

RUN mkdir /nginx_logs

# mkdir nginx access to static

RUN mkdir /static

RUN chmod 777 /static

Django
FROM python:3.8-slim-buster

EXPOSE 8000

# Keeps Python from generating .pyc files in the container

ENV PYTHONDONTWRITEBYTECODE 1

# Turns off buffering for easier container logging

ENV PYTHONUNBUFFERED 1

# Make the WORKDIR and Add everything to to it

WORKDIR /app

ADD ./test_app /app

# Install pip requirements

ADD test_app/requirements.txt .

RUN python -m pip install -r requirements.txt

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights

RUN useradd appuser && chown -R appuser /app

USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug

ENTRYPOINT ["bash", "docker-entry.sh"]