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.

  • Is it possible to run a VPN client inside a docker container?
  • unable to create docker container on windows VM, GCP
  • Unable to connect to Docker container from host
  • Is there any way to disable a service in docker-compose.yml
  • How to figure out if docker master or agent running
  • nginx gunicorn flask packed inside docker compose with redis server. getting exit status on flask part of docker compose
  • Below is a diagram of the container interactions.

    Docker container interaction

  • Persistence of Docker Data Containers
  • Writing to Kafka running in Docker from Python fails
  • Let two Containers getting linked to eachother
  • docker build and publish pull from private repo fails
  • Logstash: If-based Drop On Event After Split
  • ECS CLI - Mount EFS when launching container instance
  • 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.