Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · Dec 26, 2019

How to Make One Docker Container See The Web Service of Another One?

Hi Developers!

I stuck with one interesting problem. 

For example, let's use this template repo. If you build this container A using docker-compose and then run the container it exposes REST-API  which is available on:

localhost:52773/person/all

The question is how to make this REST-API accessible from another docker container B running on the same machine? E.g. with IRIS 2019.4 Community from this repo?

The problem is that for the second container localhost it's something which belongs to container B.

I think I need to set up a network between containers somehow. E.g. using docker-compose. But is there any simpler way?

Comments

Dmitry Maslennikov · Dec 26, 2019

The best solution would be to use docker-compose.yml

version: '3.7'
services:
  service1: 
    ....
  service2:
    ...

And each service in such configuration will be able to contact any other service by his name.

0
Mario Sanchez Macias · Feb 19, 2020

Well, the way you were guessing also should work but it is not complex at all. 

If you add the following to your docker compose: 

networks:
   msc:
     external:
        name: othercontainername_default

it should work. 

0