title: Can't communicate with simple Docker Node.js web app
body: <p>I'm just trying to learn Node.js and Docker at the same time. I have a very simple Node.js app that listens on a port and returns a string. The Node app itself runs fine when running locally. I'm now trying to get it running in a Docker container but I can't seem to reach it.</p>
  
  <p>Here's my Node app:</p>
  
  <pre><code>const http = require('http');
  
  const hostname = '127.0.0.1';
  const port = 3000;
  
  var count = 0;
  
  var server = http.createServer(function(req, res) {
      res.writeHead(200, { 'Content-Type': 'text/plain' });
      res.end("Here's the current value: " + count);
      console.log('Got a request: ', req.url);
      count++;
  });
  
  server.listen(port, hostname, () =&gt; {
      console.log(`Server running at http://${hostname}:${port}/`);
  });
  </code></pre>
  
  <p>My Dockerfile:</p>
  
  <pre><code>FROM node:latest
  
  MAINTAINER Jason
  
  ENV PORT=3000
  
  COPY . /var/www
  WORKDIR /var/www
  
  EXPOSE $PORT
  
  ENTRYPOINT ["node", "app.js"]
  </code></pre>
  
  <p>My build command:</p>
  
  <pre><code>docker build -t jason/node .
  </code></pre>
  
  <p>And my run command:</p>
  
  <pre><code>docker run -p 3000:3000 jason/node
  </code></pre>
  
  <p>The app.js file and Dockerfile live in the same directory where I'm running the commands. Doing a docker ps shows the app running but I just get a site cannot be reached error when navigating to 127.0.0.1:3000 in the browser. I've also confirmed that app.js was properly added to the image and I get the message "Server running at <a href="http://127.0.0.1:3000/" rel="nofollow noreferrer">http://127.0.0.1:3000/</a>" after running.</p>
  
  <p>I think I'm missing something really simple, any ideas?</p>