title: How to connect to docker container's link alias from host
body: <p>I have 3 separate pieces to my dockerized application:</p>
  
  <ul>
  <li><strong><code>nodeapp</code></strong>: A <code>node:latest</code> docker container running an expressjs app that returns a JSON object when accessed from <code>/api</code>. This server is also CORs enabled according to <a href="http://enable-cors.org/server_expressjs.html" rel="nofollow">this site</a>.</li>
  <li><strong><code>nginxserver</code></strong>: A <code>nginx:latest</code> static server that simply hosts an <code>index.html</code> file that allows the user to click a button which would make the XMLHttpRequest to the node server above.</li>
  <li>My <strong>host</strong> machine</li>
  </ul>
  
  <p>The <code>node:latest</code> has its port exposed to the host via <code>3000:80</code>. </p>
  
  <p>The <code>nginx:latest</code> has its port exposed to the host via <code>8080:80</code>.</p>
  
  <p>From <strong>host</strong> I am able to access both <strong>nodeapp</strong> and <strong>nginxserver</strong> <em>individually</em>: I can make requests and see the JSON object returned from the node server using <code>curl</code> from the command line, and the button (index.html) is visible on the screen when I hit <code>localhost:8080</code>. </p>
  
  <p>However, when I try clicking the button the call to <code>XMLHttpRequest('GET', 'http://nodeapp/api', true)</code> fails without seemingly hitting the <code>nodeapp</code> server (no log is present). I'm assuming this is because <strong>host</strong> does not understand <code>http://nodeapp/api</code>. </p>
  
  <p>Is there a way to tell docker that while a container is running to add its container linking alias to my hosts file? </p>
  
  <p>I don't know if my question is the proper solution to my problem. It looks as though I'm getting a CORs error returned but I don't think it is ever hitting my server. Does this have to do with accessing the application from my host machine? </p>
  
  <p><a href="https://github.com/adam-beck/docker-link-cors-problem" rel="nofollow">Here is a link to an example repo</a></p>
  
  <p><strong><em>Edit</em></strong>: I've noticed that the when using the stack that clicking the button sends <strong>a response from my nginx container</strong>. I'm confused as to why it is routing through that server as the <code>nodeapp</code> is in my <code>hosts</code> file so it should recognize the correlation there? </p>