title: docker compose Django nginx
body: <p>I've been following a tutorial for Django and docker using nginx here <a href="http://ruddra.com/2016/08/14/docker-django-nginx-postgres/" rel="nofollow noreferrer">http://ruddra.com/2016/08/14/docker-django-nginx-postgres/</a>. but I have another VM with an exposed port of 8000 so I changed it to 8100 but left the other at 8000</p>
  
  <p>this is my compose file:</p>
  
  <pre><code>version: '3'  
  services:  
    nginx:
      image: nginx:latest
      container_name: ngnix01
      ports:
        - "8100:8000"
      volumes:
        - ./code:/code
        - ./config/nginx:/etc/nginx/conf.d
      depends_on:
        - web
    web:
      build: .
      container_name: django01
      command: bash -c "python manage.py makemigrations &amp;&amp; python manage.py migrate &amp;&amp; gunicorn mydjango.wsgi -b 0.0.0.0:8000"
      depends_on:
        - db
      volumes:
        - ./code:/code
      expose:
        - "8000"
    db:
      image: postgres:latest
      container_name: postgres01
  </code></pre>
  
  <p>nginx config:</p>
  
  <pre><code>upstream web {  
    ip_hash;
    server web:8000;
  }
  
  server {
  
      location /static/ {    
          autoindex on;    
          alias /static/; 
      }
  
      location / {
          proxy_pass http://web/;
      }
      listen 8000;
      server_name localhost;
  }
  </code></pre>
  
  <p>and I'm getting the error when I docker-compose up</p>
  
  <pre><code>attaching to postgres01, django01, ngnix01
  django01 | Traceback (most recent call last):
  django01 |   File "manage.py", line 8, in &lt;module&gt;
  ngnix01  | 2017/08/25 10:25:01 [emerg] 1#1: host not found in upstream "web:8000" in /etc/nginx/conf.d/django.conf:3
  django01 |     from django.core.management import execute_from_command_line
  ngnix01  | nginx: [emerg] host not found in upstream "web:8000" in /etc/nginx/conf.d/django.conf:3
  django01 | ModuleNotFoundError: No module named 'django.core'
  django01 exited with code 1
  </code></pre>
  
  <p>which makes me think nginx can't contact unicorn on port 8000? I think my compose file is correct? port on the left is port to expose, port on the right is the one in the container?</p>
  
  <p>or is it that when using multiple images they speak to each other externally? </p>
  
  <p>Thanks</p>
  
  <p>EDIT:
  included dockerfile</p>
  
  <pre><code>#set base image
  FROM python:latest
  ENV PYTHONUNBUFFERED 1
  
  #install  dependencies
  
  RUN sed -i "s#jessie main#jessie main contrib non-free#g" /etc/apt/sources.list
  
  RUN apt-get update -y \
      &amp;&amp; apt-get install -y apt-utils python-software-properties libsasl2-dev python3-dev libldap2-dev libssl-dev libsnmp-dev snmp-mibs-downloader
  
  ENV APP_USER itapp
  ENV APP_ROOT /code
  RUN mkdir /code;
  RUN groupadd -r ${APP_USER} \
      &amp;&amp; useradd -r -m \
      --home-dir ${APP_ROOT} \
      -s /usr/sbin/nologin \
      -g ${APP_USER} ${APP_USER}
  
  WORKDIR ${APP_ROOT}
  
  RUN mkdir /config
  ADD config/requirements.txt /config/
  RUN pip install -r /config/requirements.txt
  
  USER ${APP_USER}
  ADD . ${APP_ROOT}
  </code></pre>