title: nginx gunicorn with docker: how to use multiple dockerfiles
body: <p>I'm using the following <a href="http://pawamoy.github.io/2018/02/01/docker-compose-django-postgres-nginx.html" rel="nofollow noreferrer">example</a> to build a django-postgres-nginx-gunicorn web server. I'd like to have separated folders for each container. The following structure of the project works correctly. The main Dockerfile is used for the hello app (the django project):</p>
  
  <pre><code>svm3_03
  |____Dockerfile
  |____config
  |    |____gunicorn
  |    |    |____conf.py
  |    |____nginx
  |    |    |____conf.d
  |    |         |____local.conf
  |    |____db
  |         |____db_env
  |____docker
  |    |__db
  |       |__Dockerfile
  |       |__dataForDB
  |__docker-compose.yml
  |__hello
  </code></pre>
  
  <p>the docker-compose.yml looks like this:</p>
  
  <pre><code>version: '3'
  ...
  services:
     djangoapp:
        build:
           context: .
  ...
  </code></pre>
  
  <p>and the Dockerfile has the following line:</p>
  
  <pre><code>CMD ["gunicorn", "-c", "config/gunicorn/conf.py", "--bind", ":8000", "--chdir", "hello", "hello.wsgi:application"]
  </code></pre>
  
  <p>Everything works. Now I tried to have the same structure as the DB image also for the django app so I move the main Dockerfile and the hello directory inside the docker folder... I created a new folder inside the docker folder with name djangoapp and I moved there the Dockerfile and the hello folder. The new structure is the following:</p>
  
  <pre><code>svm3_03
  |____config
  |    |____gunicorn
  |    |    |____conf.py
  |    |____nginx
  |    |    |____conf.d
  |    |         |____local.conf
  |    |____db
  |         |____db_env
  |____docker
  |    |__db
  |    |  |__Dockerfile
  |    |  |__dataForDB
  |    |__djangoapp
  |       |__Dockerfile
  |       |__hello
  |__docker-compose.yml
  </code></pre>
  
  <p>All I did then was to change the context line in the docker-compose.yml file like this:</p>
  
  <pre><code>version: '3'
  ...
  services:
     djangoapp:
        build:
           context: ./docker/djangoapp
  ...
  </code></pre>
  
  <p>Now I get the following error:</p>
  
  <pre><code>djangoapp_1_7b3c77a4b939 | Error: can't chdir to 'hello'...
  </code></pre>
  
  <p>which is due to gunicorn and the command line CMD inside the djangoapp Dockerfile. Clearly changing the context in docker-compose.yml is not enough... any idea what am I missing?</p>
  
  <p>Thanks </p>
  
  <p><strong>UPDATE:</strong>
  Here is the full dockerfile:</p>
  
  <pre><code>FROM python:2
  
  ENV PYTHONUNBUFFERED 1
  RUN mkdir -p /opt/services/djangoapp/src
  
  WORKDIR /opt/services/djangoapp/src
  
  COPY . /opt/services/djangoapp/src
  RUN pip install --no-cache-dir -r hello/requirements.txt
  RUN cd hello &amp;&amp; python manage.py collectstatic --no-input
  
  EXPOSE 8000
  CMD ["gunicorn", "-c", "config/gunicorn/conf.py", "--bind", ":8000", "--chdir", "hello", "hello.wsgi:application"]
  </code></pre>