title: EADDRNOTAVAIL when Dockerizing Node.js app
body: <p>With the following app, I am able to start it manually via npm install / node app.js. The issue is with trying to run the app via a Docker container.</p>
  
  <p>Apart from what the rest of the app is (which doesn't matter because running the Docker container doesn't even get that far), the Dockerfile pulls the code from GitHub, switches to that directory, then runs app.js (which pulls the host and port from a config.json file). Attempting to run the container with the IP address of the server (what it should be listening on) results in the following error:</p>
  
  <pre><code>uncaughtException: Error: listen EADDRNOTAVAIL
  Error: listen EADDRNOTAVAIL
  at errnoException (net.js:905:11)
  at Server._listen2 (net.js:1024:19)
  at listen (net.js:1065:10)
  at net.js:1147:9
  at dns.js:72:18
  at process._tickCallback (node.js:442:13)
  at Function.Module.runMain (module.js:499:11)
  at startup (node.js:119:16)
  at node.js:929:3
  </code></pre>
  
  <p>Changing the port does nothing to resolve the issue. I've included the relevant files below (with certain sections replaced with {pseudocode}). Any help would be <em>immensely</em> appreciated, because I'm absolutely hopeless when it comes to Docker.</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM    centos:centos6
  RUN     rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
  RUN     yum install -y npm git
  RUN git clone {repo.git}
  COPY . /src
  RUN npm install
  CMD ["node", "app.js"]
  </code></pre>
  
  <p>config.json:</p>
  
  <pre><code>{
      "app_host": "{IP of server}",
      "app_port": "20000"
  }
  </code></pre>
  
  <p>app.js:</p>
  
  <pre><code>var server = app.listen(config_json.app_port, config_json.app_host, function () {
  
    var host = server.address().address;
    var port = server.address().port;
  
    console.log('\n  listening at http://%s:%s', host, port);
  
  });
  
  module.exports = app;
  </code></pre>