Sekru
Sekru

Reputation: 515

Call from docker ui container to api container

Here is my docker-compose

services:
  api:
    image: api
    container_name: api
    ports:
      - "3000:3000"
    external_links:
      - front
    networks:
      - global
  front:
    image: front
    container_name: front
    ports:
      - "8080:80"
    external_links:
      - api
    networks:
      - global

networks:
   global:

I'm trying to call api from ui container. Here is the call url: http://api:3000/api/search?query=ihpone&page=1&minPrice=0&maxPrice=9999 I'm getting error ERR_NAME_NOT_RESOLVED

Someone can help me ? How to solve my issue. How make request from ui container to api container?

Upvotes: 1

Views: 918

Answers (1)

Dejan
Dejan

Reputation: 353

When you're opening your UI application on browser you're actually downloading it to host (your machine where docker is installed) and then you're making a call to API.

So in your example you need to set url in your UI application's configuration to be: localhost:3000 instead of api:3000

  • localhost:3000 - is to hit an app in a docker container from a host.
  • api:3000 - is to hit an app in a docker container from another docker container.

Upvotes: 4

Related Questions