2

I'm using two different docker-compose setup for two different projects. I need to make an HTTP request from one to other and tried to send it like http://localhost:8050/api but keep getting cURL error even though it is working on Postman. Here are the docker-compose files:

File 1 (Request receiver)

version: '3'

services:
  app:
    container_name: core
    build: .cloud/php
    image: app-core
    ports:
      - "9050:9000"
    volumes:
      - ./:/var/www:cached
    networks:
      - core_network

  nginx:
    container_name: core.nginx
    image: nginx
    ports:
      - "8050:8000"
    volumes:
      - .cloud/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:cached
      - ./:/var/www:cached
    depends_on:
      - app
    networks:
      - core_network

  pgres:
    container_name: core.postgres
    image: postgres
    restart: always
    ports:
      - "54321:5432"
    environment:
      POSTGRES_DB: sampleuser
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: example
    volumes:
      - .cloud/postgres/data:/var/lib/postgresql/data
    networks:
      - core_network
networks:
  core_network:
    driver: bridge

File 2 (Request sender)

version: '3'

services:
  app:
    container_name: b2c
    build: .cloud/php
    image: app-b2c
    ports:
      - "9055:9000"
    volumes:
      - ./:/var/www:cached
    networks:
      - b2c_network

  nginx:
    container_name: b2c.nginx
    image: nginx
    ports:
      - "8055:8000"
    volumes:
      - .cloud/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:cached
      - ./:/var/www:cached
    depends_on:
      - app
    networks:
      - b2c_network 
networks:
  b2c_network:
    driver: bridge
lostbyte
  • 466
  • 1
  • 8
  • 21
  • I did some more searching and best solution I came across is described in here: https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects as it suggest; these two compose files must be in the same network in order to communicate. – lostbyte Jan 19 '21 at 21:12
  • Couldn't make it work. All I can do is to grab the container assigned gateway id with `docker inspect `and use it on the http request as the host. – lostbyte Jan 19 '21 at 21:31

1 Answers1

10

For anyone struggling you can make requests like: http://host.docker.internal:8050

lostbyte
  • 466
  • 1
  • 8
  • 21