title: Calling a service running in a docker container from an angular2 app
body: <p>I have a UI application which is developed in Angular2. I also have a couple of services that are developed in Spring Boot. I am trying to call a Spring Boot service from the Angular application.</p>
  
  <p>Below is my docker-compose.yml</p>
  
  <pre><code>version: '2'
  networks:
    mynet:
  services:
    ui:
      image: uiimg
      networks:
        - mynet
      ports:
        - "4200:4200"
    srvc:
      image: scservice
      networks:
        - mynet
      ports:
        - "8080:8080"
    testsrvc:
      image: testsrvc
      networks:
        - mynet
      ports:
        - "8081:8081"      
  </code></pre>
  
  <p>This is how I am calling the service defined by "srvc" from angular.</p>
  
  <pre><code>return this.http.get("http://srvc:8080/test").map(result =&gt; result.json());
  </code></pre>
  
  <p>But I am getting the error 
      srvc:8080/test Failed to load resource: net::ERR_NAME_NOT_RESOLVED</p>
  
  <p>However, I can call <a href="http://srvc:8080/test" rel="nofollow noreferrer">http://srvc:8080/test</a> from another service in "testsrvc" without any issues. </p>
  
  <p>My understanding is that since the UI request originates from the browser, it has no means of knowing what "srvc" is, whereas since "testsrvc" also runs in a container, it can link to "srvc"</p>
  
  <p>So how should I be calling "srvc" from angular?</p>
  
  <p>P.S: I tried <a href="http://srvc:8080/test" rel="nofollow noreferrer">http://srvc:8080/test</a> and <a href="http://srvc/test" rel="nofollow noreferrer">http://srvc/test</a>
  Neither is working.</p>
  
  <p>The angular application in the container is up and running and I am able to access it from <a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a></p>