title: Why is my docker port specification failing?
body: <p>I have deployed a container using the following Dockerfile, but the website is producing this error.</p>
  <p>What am I doing wrong?</p>
  <p><em>Unable to connect
  Firefox can’t establish a connection to the server at localhost:8080.What am I doing wrong?</em></p>
  <p>Here is my Dockerfile</p>
  <pre><code>FROM node:lts-alpine
  
  # Create a group and user
  RUN addgroup -S group &amp;&amp; adduser -S user -G group
  
  # Set the working directory
  WORKDIR /home/user/app
  ENV PATH=&quot;/home/user/app/:${PATH}&quot;
  
  # Copy the current directory contents into the container
  COPY ./package.json ./
  
  COPY --chown=user:group . .
  
  # Install any needed packages specified in requirements.txt
  RUN npm install 
  
  
  EXPOSE 8080
  USER user
  
  # Run server.js when the container launches
  ENTRYPOINT [&quot;npm&quot;, &quot;start&quot;]
  
  </code></pre>
  <p>the starting command I am using is</p>
  <p><em>docker run -d -p=8080:8080 --name test test</em></p>
  <p>The server is supposed to be deployed on port 8080</p>
  <pre><code>function startServer(server, port, host) {
    function onError(error) {
      server
        .removeListener('error', onError)
        .removeListener('listening', onSuccess)
      if (error.code === 'EADDRINUSE') {
        startServer(server, ++port, host)
      }
    }
  
    function onSuccess() {
      console.log(
        `listening at: (host = ${host}, port = ${server.address().port})`
      )
    }
    server.listen(port, host)
    .on('error', onError)
    .on('listening', onSuccess)
  }
  
  
  var port = 8080;
  const host = 'localhost'
  const server = http.createServer(app)
  
  console.log(&quot;The server is now listening to port &quot; + port)
  startServer(server, port, host)
  </code></pre>
  <p>and I am getting the expected output on the console</p>
  <pre><code>The server is now listening to port 8080
  listening at: (host = localhost, port = 8080)
  </code></pre>
  <p>but when I run netstat in the container, port 8080 is not open</p>
  <pre><code>~/app $ netstat -a
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       
  tcp        0      0 localhost:http-alt      0.0.0.0:*               LISTEN      
  tcp        0      0 c6ca9e617fc9:57750      104.16.17.35:https      TIME_WAIT   
  tcp        0      0 c6ca9e617fc9:57748      104.16.17.35:https      TIME_WAIT   
  Active UNIX domain sockets (servers and established)
  Proto RefCnt Flags       Type       State         I-Node Path
  </code></pre>