Connect to host A from docker running on host B

3588 views docker

I develop distributed system and I consider situation: My application is working in docker that is running on host A and I want to call api from other service that is running on physical host B (without docker). Could I do it calling an IP or DNS address?

Other situation that concerns above problem: I develop distributed system locally using docker-compose and I define there services: ServiceA, ServiceB and so on. If ServiceA has to call to ServiceB on port 8080 I call http://ServiceB:8080/ and it works fine. In production each service should work on different host with different IP. So is it good way I will run each service on different host and I will call from ServiceA to ServiceB by http://<IP_of_ServiceB>:8080 instead of using service name?

answered question

1 Answer


First question, yes, just make sure ports are exposed and reachable from the other host.

Second question, you can still do that (write down the ip of host B in an env or so). Or, you may want to consider using docker swarm to deploy your production stack. Combined with an overlay network, which makes your 2 hosts act like one, you can continue call like http://ServiceB:3000/

version: '3'
    image: serviceA
      - "8080:8080"
    networks: swarm-net

    image: serviceB
    networks: swarm-net
      - "3000:3000"

    driver: overlay

posted this

Have an answer?


Please login first before posting an answer.