title: Deploy to docker with nginx, django, daphne
body: <p>I want to deploy my service to docker.</p>
  
  <p>and my service is developed using python+django and django-channels</p>
  
  <p><code>
  ── myproject
      ├── myproject
      │   ├── settings.py
      │   ├── urls.py
      │   ├── asgi.py
      │   ├── ...
      ├── collected_static
      │   ├── js
      │   ├── css
      │   ├── ...
      ├── nginx
      │   ├── Dockerfile
      │   ├── service.conf
      ├── requirements.txt
      ├── manage.py
      ├── Dockerfile
      └── docker-compose.yml
  </code></p>
  
  <p>myproject/Dockerfile :</p>
  
  <pre><code>FROM python
  ENV PYTHONUNBURRERED 1
  
  RUN mkdir -p /opt/myproject
  WORKDIR /opt/myproject
  ADD . /opt/myproject
  
  RUN pip install -r requirements.txt
  RUN python manage.py migrate
  </code></pre>
  
  <p>myproject/docker-compose.yml:</p>
  
  <pre><code>version: '2'
  services:
    nginx:
      build: ./nginx
      networks:
        - front
        - back
      ports:
        - "80:80"
      depends_on:
        - daphne
    redis:
      image: redis
      networks:
        - "back"
      ports:
        - "6379:6379"
    worker:
      build: .
      working_dir: /opt/myproject
      command: bash -c "python manage.py runworker"
      environment:
        - REDIS_HOST=redis
      networks:
        - front
        - back
      depends_on:
        - redis
      links:
        - redis
    daphne:
      build: .
      working_dir: /opt/myproject
      command: bash -c "daphne -b 0.0.0.0 -p 8000 myproject.asgi:channel_layer"
      ports:
        - "8000:8000"
      environment:
        - REDIS_HOST=redis
      networks:
        - front
        - back
       depends_on:
        - redis
       links:
        - redis
    networks:
      front:
      back:
  </code></pre>
  
  <p>myproject/nginx/Dockerfile</p>
  
  <pre><code>FROM nginx
  COPY service.conf /etc/nginx/sites-enabled/
  </code></pre>
  
  <p>myproject/nginx/service.conf</p>
  
  <pre><code>server {
    listen 80;
    server_name example.com #i just want to hide domain name..
    charset utf-8;
    client_max_body_size 20M;
  
    location /static/ {
      alias /opt/myproject/collected_static/;
    }
  
    location / {
      proxy_pass http://0.0.0.0:8000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
  
      proxy_redirect off;
      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;
    }
  }
  </code></pre>
  
  <p>and i write a command <code>docker-compose up -d</code>, nginx and daphne work well.</p>
  
  <p>but when i connected to example.com:80, i just can see nginx default page.</p>
  
  <p>and when i connected to example.com:8000, i just can see myproject's service page. (but cannot see static files)</p>
  
  <p>I want to link nginx and daphne service! what should I do? please help me.</p>
  
  <ul>
  <li>when i just deploy with nginx+daphne+django without docker, my service works well.</li>
  </ul>