title: Not able to map Nginx Port 80 with docker container port 80
body: <p>I'm running a NodeJS app that is running on port 4242 and here's the dockefile, docker-compose and nginx conf looks like this</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM node:12-alpine
  COPY package.json package-lock.json ./
  RUN npm ci
  COPY . .
  EXPOSE 4242
  CMD node index.js.
  </code></pre>
  <p><strong>Docker Compose</strong></p>
  <pre><code>services:
     web:
        build: .
     ports:
        - &quot;80:4242&quot;
     environment:
     DATABASE_URL: &lt;DB_URL&gt;
     depends_on:
        - db
  command: &gt;
      npm run start&quot;
  </code></pre>
  <p><strong>NGINX</strong></p>
  <pre><code>server {
  listen 80;
  server_name server_name;
  
  location / {
          try_files $uri $uri/ =404;
          auth_basic &quot;Restricted Content&quot;;
          auth_basic_user_file /etc/nginx/.htpasswd;
          proxy_pass http://localhost:80;
  }
  }
  </code></pre>
  <p>I wanted to make this app accessible via port 80 through Nginx along with with basic auth on port 80 but I'm not able to map the port correctly.</p>
  <p><strong>EDIT:</strong> I always get port already in use error because Nginx by default is listening on port 80 whereas and in docker-compose I'm mapping 80 with the 4242 which Dockerfile is exposing</p>
  <p>Thanks in advance</p>