0

I am playing around with Docker and stuff, using this docker-compose.yml:

version: '3.4'
services:
  frontend:
    image: apmimg:latest
    networks:
      - core-infra    
    ports: 
      - 8080:80
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure


  backend:
    image: productsapi:latest
    volumes:
      - myvol:/opt/myvol
    networks:
      - core-infra
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure


networks:
  core-infra:
    driver: overlay

volumes:
  myvol: 
    driver: local

And when I ssh into frontend and ping backend "ping mysite_backend" it does work.

But when I try to make a HTTP request from my Node.js code:

private _productUrl = "http://mysite_backend/api/products";  

getProducts(): Observable<IProduct[]>
{
    let url = this._productUrl;
    return this._http.get<IProduct[]>(url)
        .do(data => console.log('All: ' + JSON.stringify(data)))
        .catch(this.handleError);
}

I get a "Failed to load resource: net::ERR_NAME_NOT_RESOLVED", even in the same host.

Any ideas on what's wrong?

Raul Kist
  • 331
  • 3
  • 8
  • You have to expose the ports of your backend service to the host machine. – Vamsi Apr 05 '18 at 05:35
  • Does your `productsapi:latest` is listen on port 80? Exposing port to host machine is not necessary – Markus Apr 05 '18 at 07:12
  • Yes. productsapi is listening in port 80. If I expose it like 8081:80 and access *http://localhost:8081/api/products* I get the response I want but it is not the environment I want to build. – Raul Kist Apr 05 '18 at 09:19

0 Answers0