We\'re dockerizing our micro services app, and I ran into some discovery issues.
The app is configured as follows:
When the a service is started in \'non-local\'
But one service can not interact with another service since they are not on the same machine and tcp://localhost:61001 will obviously not work.
Actually, they can. You are right that tcp://localhost:61001
will not work, because using localhost
within a container would be referring to the container itself, similar to how localhost
works on any system by default. This means that your services cannot share the same host. If you want them to, you can use one container for both services, although this really isn't the best design since it defeats one of the main purposes of Docker Compose.
The ideal way to do it is with docker-compose links, the guide you referenced shows how to define them, but to actually use them you need to use the linked container's name in URLs as if the linked container's name had an IP mapping defined in the original container's /etc/hosts
(not that it actually does, but just so you get the idea). If you want to change it to be something different from the name of the linked container, you can use a link alias, which are explained in the same guide you referenced.
For example, with a docker-compose.yml
file like this:
a:
expose:
- "9999"
b:
links:
- a
With a
listening on 0.0.0.0:9999
, b
can interact with a
by making requests from within b
to tcp://a:9999
. It would also be possible to shell into b
and run
ping a
which would send ping requests to the a
container from the b
container.
So in conclusion, try replacing localhost
in the request URL with the literal name of the linked container (or the link alias, if the link is defined with an alias). That means that
tcp://:61001
should work instead of
tcp://localhost:61001
Just make sure you define the link in docker-compose.yml
.
Hope this helps