I have a docker setup made up of a compose file with 2 services and one app running in a standalone container.
My compose file has this structure
version: '3'
services:
synapse:
image: docker.io/matrixdotorg/synapse:latest
depends_on:
- db
ports:
- 8008:8008
db:
image: docker.io/postgres:12-alpine
# other commandds
When I do docker-compose up a default network called synapse_default. And the synapse service is able to connect to the db using db as host. That is my postgres URL looks like this postgres://synapse:synapse@db/postgres. You'll notice the host name is db and this works because they're been run in the same docker network.
Now I have a standalone application in another container I run with docker run --network=synapse_default and this app is able to connect to the synapse and db services using the service names as host addresses.
My problem now is to have the synapse service talk to standalone application. Since this standalone application was not part of the compose file, it does not have a service name hence I'm not sure what to specify as the host for the synapse service to be able to reach the standalone application.
I got this to work by specifying
--hostnamewhen running my standalone container.I'm only keep this question open because I already have one response but this was a weak question as I failed to do proper research. A quick
docker run --helpprovided me with the answer I needed.