title: Docker: Nginx - [emerg] host not found in upstream
body: <p>I am building a Rails application and I am setting up the application for deployment on docker with Nginx as the webserver. I am, however, having issues setting up Nginx with Docker for the application.</p>
  
  <p>I keep getting this error when I run <code>docker-compose up</code>:</p>
  
  <blockquote>
    <p>nginx: [emerg] host not found in upstream "app:3000" in /etc/nginx/conf.d/mailing_list.conf</p>
  </blockquote>
  
  <p>Here's my <code>docker-compose.yml</code> file:</p>
  
  <pre><code>version: '3'
   
  services:
    app:
      build:
        context: .
        dockerfile: ./docker/${RAILS_ENV}/Dockerfile
      depends_on:
        - database
      ports:
        - "3000:3000"
      restart: always
      volumes:
        - .:/app
        - gem-cache:/usr/local/bundle/gems
        - node-modules:/app/node_modules
      env_file:
        - .env
      environment:
        RAILS_ENV: ${RAILS_ENV}
        RACK_ENV: ${RACK_ENV}
   
    database:
      image: postgres:12.1
      expose:
        - "5432"
      restart: always
      env_file:
        - .env
      environment:
        POSTGRES_USER: ${DATABASE_USER}
        POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
        POSTGRES_DB: ${DATABASE_NAME}
        POSTGRES_HOST_AUTH_METHOD: ${DATABASE_HOST}
      volumes:
        - postgres-data:/var/lib/postgresql/data
        - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    nginx:
      build:
        context: .
        dockerfile: ./docker/nginx/Dockerfile
      depends_on:
        - app
      ports:
        - "8080:8080"
      restart: always
      volumes:
        - .:/app
        - nginx-config:/etc/nginx
        - nginx-log:/var/log/nginx
   
  volumes:
    gem-cache:
    nginx-config:
    nginx-log:
    node-modules:
    postgres-data:
  </code></pre>
  
  <p>And here's my <code>nginx.conf</code> file:</p>
  
  <pre><code>upstream app {
    server app:3000;
  }
   
  server {
      listen 8080;
      listen [::]:8080;
   
      root app/public;
      index index.html index.htm;
   
      server_name localhost;
   
      location /app {
        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-Proto $scheme;
        proxy_pass http://app;
      }
  }
  </code></pre>
  
  <p>I have tried a lot of solutions, but none seems to work.</p>
  
  <p>I keep getting this error when I run <code>docker-compose up</code>:</p>
  
  <blockquote>
    <p>nginx: [emerg] host not found in upstream "app:3000" in /etc/nginx/conf.d/mailing_list.conf</p>
  </blockquote>
  
  <p>Any form of help would be appreciated. Thank you.</p>