Nginx not serving static files with docker-compose and django (13: Permission denied)

I’m using docker-compose and docker-machine to setup a dev environment with multiple containers. I have a container for nginx, which acts as a proxy to my django application and also serves static files). I have also a container for the django app, one for postgresql and one for postgresdata.
The directory structure is the following:

code/
  -- nginx/
       Dockerfile
       nginx.conf
  -- web/
       django-project/
       static/
       Dockerfile
       manage.py
       requirements.txt
  .env
  docker-compose.yml
  production.yml

In order to run the application, I use docker-machine:

  • Remove /bin/busybox at build time
  • Openshift : pods not being deleted
  • When running a Django dev server with docker/fig, why is some of the log output hidden?
  • splitting docker stdout and stderr with fluentd fluent-plugin-rewrite-tag-filter plugin
  • Docker can't connect to docker daemon
  • docker stop spark container from exiting
  • docker-machine create -d virtualbox dev
    

    then I run:

    docker-compose build
    docker-compose up -d
    

    And the application is up and running on the ip of the machine. The problemm is that nginx cannot serve static files, because it hasn’t the permission (13: Permission denied).

    My setup is the following:

    nginx Dockerfile:

    # Set nginx base image
    FROM nginx
    
    # Copy custom configuration file from the current directory
    COPY nginx.conf /etc/nginx/nginx.conf
    

    ngin.conf:

    worker_processes 1;
    
    events {
    worker_connections 1024;
    }
    
    http {
    
    server {
        listen 80;
        server_name example.org;
    
        access_log /dev/stdout;
        error_log /dev/stdout info;
    
        location /static/ {
            alias /usr/src/app/static/;
        }
    
        location / {
            proxy_pass http://web:8000;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
    }
    

    django Dockerfile:

    FROM python:3.5.1-onbuild
    

    docker-compose.yml:

    web:
      restart: always
      build: ./web
      expose:
        - "8000"
      links:
        - postgres:postgres
      volumes:
        - /usr/src/app/static
      env_file: .env
      command: /usr/local/bin/gunicorn collecteev_django.wsgi:application -w 2 -b :8000
    
    nginx:
      restart: always
      build: ./nginx/
      ports:
        - "80:80"
      volumes_from:
        - web
      links:
        - web:web
    
    postgres:
      restart: always
      image: postgres:latest
      volumes_from:
        - data
      ports:
        - "5432:5432"
    
    data:
      restart: always
      image: postgres:latest
      volumes:
        - /var/lib/postgresql
      command: "true"
    

    Versions:

    docker: 1.9.1
    docker-compose: 1.5.2
    docker-machine: 0.5.4
    

    Any help with this problem would be highly appreciated, thanks!

  • Build error using cmake in docker
  • Docker for Windows Beta release notes and version history
  • How to prevent zombie services with consul and gliderlabs/registrator?
  • Docker: Unable to execute RUN command after ADD when starting from scratch
  • Docker and sensitive information used at run-time
  • udp traffic with Iperf for haproxy
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.