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.
You can find the name of your 'standalone application' with
docker ps:fooin the example above is the name you can use. You can also use205f1583e0a0(CONTAINER ID) if you find it convenient. If you wish to use a specific name (likefooin the example), you have to run the standalone application with--nameargument: