title: docker-compose uwsgi connect() failed (111: Connection refused)
body: <p>I made infra with docker.</p>
  
  <p>Also used docker-compose to tide each container.</p>
  
  <p>Below is images that I used.</p>
  
  <ul>
  <li>nginx:latest</li>
  <li>mongo:latest</li>
  <li>python:3.6.5</li>
  </ul>
  
  <p>To deploy flask webserver, I used uwsgi.</p>
  
  <p>(uwsgi installed at python:3.6.5)</p>
  
  <p>[docker-compose.yml]</p>
  
  <pre><code>version: '3.7'
  
  services:
    nginx:
      build: 
        context: .
        dockerfile: docker/nginx/dockerfile
      container_name: nginx
      hostname: nginx-dev
      ports:
        - '80:80'
      networks: 
        - backend
      links:
        - web_project
  
    mongodb:
      build:
        context: .
        dockerfile: docker/mongodb/dockerfile
      container_name: mongodb
      hostname: mongodb-dev
      ports:
        - '27017:27017'
      networks:
        - backend
  
    web_project:
      build:
        context: .
        dockerfile: docker/web/dockerfile
      container_name: web_project
      hostname: web_project_dev
      ports:
        - '5000:5000'
      networks:
        - backend
      tty: true
      depends_on:
        - mongodb
      links:
        - mongodb
  
  
  networks: 
    backend:
      driver: 'bridge'
  </code></pre>
  
  <p>[/docker/nginx/dockerfile]</p>
  
  <pre><code>FROM nginx:latest
  
  COPY . ./home
  WORKDIR home
  RUN rm /etc/nginx/conf.d/default.conf
  COPY ./config/nginx.conf /etc/nginx/conf.d/default.conf
  </code></pre>
  
  <p>[/config/nginx.conf]</p>
  
  <pre><code>upstream flask {
      server web_project:5000;
  }
  server {
      listen 80;
  
      location / {
          uwsgi_pass flask;
          include /home/config/uwsgi_params;
      }
  }
  </code></pre>
  
  <p>[/docker/web/dockerfile]</p>
  
  <pre><code>FROM python:3.6.5
  
  COPY . ./home
  WORKDIR home
  RUN pip install -r app/requirements.txt
  RUN apt-get update &amp;&amp; apt-get install -y uwsgi-plugin-python
  RUN uwsgi --ini config/uwsgi.ini
  </code></pre>
  
  <p>[uwsgi.ini]</p>
  
  <pre><code>[uwsgi]
  chdir = /home/app
  socket = :5000
  chmod-socket = 666
  logto = /home/web.log
  master = true
  process = 2
  daemonize = /home/uwsgi.log
  </code></pre>
  
  <p>Defined <code>socket = :5000</code>.</p>
  
  <p>After build/up and access to website, it throws 502 bad gateway throw error to console.</p>
  
  <p><code>nginx          | 2018/11/12 06:28:55 [error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.27.0.1, server: , request: "GET / HTTP/1.1", upstream: "uwsgi://172.27.0.3:5000", host: "localhost"</code></p>
  
  <p>I searched in google long times, but I can't find the solution.</p>
  
  <p>Is there any solution here?</p>
  
  <p>Thanks.</p>