Docker compose: angular container can't send request to backend container

Viewed 387

When i worked without docker, i sended requests to this basic path

http://localhost:8080/api/v3

Now i am trying send to:

http://backend:8080/api/v3

But i get

GET http://backend:8080/api/v3/developers net::ERR_NAME_NOT_RESOLVED

How look my ui container:

  front:
    image: myimage
    container_name: front
    build:
      context: path
    environment:
      API_HOST: backend
      API_PORT: 8080
    ports:
      -  4200:4200
    depends_on:
      - backend

P.S. backend works perfectly

1 Answers

You are sending a request from your front wich is hosted by your navigator into your local host environment (127.0.0.1). So you can not send a request to your backend because your are outside of the docker-compose internal network. Replace API_HOST=127.0.0.1 and make sure sur your backend container expose the 8080 port.

Related