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:

  • Linked container IP not in hosts
  • How to create docker machine with specific version?
  • logspout write: connection refused
  • docker mounts host's / directory to container's / in debian wheezy 7.8
  • Docker Redis container orderly shutdown
  • Cannot connect via PHP to docker mysql
  • 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!

  • Docker & Amazon Beanstalk - Deploy an Angular application
  • Docker using separate lib/bin
  • docker-compose : Issue with .env path
  • Where to find more explicit errors given container error status codes?
  • How to set mysql username in dockerfile
  • Access localhost PostgreSQL & Redis from a dockerized app
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.