Docker communication between apps in separate containers

I have been looking everywhere for this answer. To me it seems like an obvious question, however, the answer has eluded me.

My current setup is, I have redis, mongodb and two api servers on the same bridge network. The first server serves as a gateway api that does all the auth, and exposes certain api calls. The backend api is the one that handles all the db interactions and data munging. If I hit the backend (inner) api alone, I am able to see the contents (this api would not be exposed in real production environment). However, if I make the same request from within the gateway api, I am not able to hit the backend (inner) api that is also part of the bridged network I created.

  • Artifactory allow anonymous access for docker pull
  • Selenium webdriver with Phantomjs save_screenshot doesn't work in Docker container
  • java -jar lib/kvstore.jar ping - ConnectException when using IPAddress
  • Can Docker containers run in Windows IoT Core
  • ssh into boot2docker - can you see -v folders from within boot2docker vm
  • Node cli program not working in windows machine
  • Below is a diagram of the container interactions.

    Docker container interaction

  • Unable to upgrade pip in docker build
  • How is a data-only container in Docker getting data?
  • Error Setting up Containerized Sensu-server and client, to monitor Docker
  • Get the right domain name in Eureka on Docker
  • Restart one service in docker swarm stack
  • Create a local end-to-end development environment
  • One Solution collect form web for “Docker communication between apps in separate containers”

    I still use legacy linking, but I’m a little bit familiar with this. I think the problem is that you are trying to hit “localhost” from inside your gateway container. The inner API container cannot be resolved as “localhost” inside of the gateway API container. You are able to hit “localhost:8099” from the host machine or externally because of the port mapping, but none of your other containers will be able to resolve that address/port because they ‘think’ it’s a remote machine.

    Here’s a way to test what I’m thinking. In your host’s shell, run the bridge inspect command shown here. Copy the IP address from Containers.<inner-api-hash>.IPV4. Then open a shell in the gateway container with docker exec -it <gateway-id> /bin/bash and then use curl or wget to see if you can hit that IP address you copied.

    If my thinking is correct, you will see that you must use your inner-API node’s Docker assigned IP address from the other containers. Amongst other options, you can start containers with a static IP address as shown here.

    This is starting to escape the scope of my knowledge, but you can also configure a container DNS. Configure container DNS.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.