title: How to run Nginx docker container with custom config?
body: <p>I have a Dockerfile and custom Nginx configuration file (in the same directory with Dockerfile) as follows:</p>
  <p>Dockerfile:</p>
  <pre><code>FROM nginx
  
  COPY nginx.conf /etc/nginx/nginx.conf
  </code></pre>
  <p><code>nginx.conf</code> file:</p>
  <pre><code>upstream myapp1 {
            least_conn;
            server http://example.com:81;
            server http://example.com:82;
            server http://example.com:83;
      }
  
  server {
            listen 80;
  
            location / {
              proxy_pass http://myapp1;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection 'upgrade';
              proxy_set_header Host $host;
              proxy_cache_bypass $http_upgrade;
            }
      }
  </code></pre>
  <p>I run these two commands:</p>
  <pre><code>docker --tls build -t nginx-image .
  docker --tls run -d -p 80:80 --name nginx nginx-image
  </code></pre>
  <p>Then I checked out all running containers but it didn't show up. When I searched Nginx container's log, I found this error message:</p>
  <blockquote>
  <p>[emerg] 1#1: unknown directive &quot;upstream&quot; in
  /etc/nginx/nginx.conf:1 Nginx: [emerg] unknown directive
  &quot;upstream&quot; in <code>/etc/nginx/nginx.conf</code>:</p>
  </blockquote>
  <p>What am I missing?</p>