---
version: \'3.7\'
networks:
sydney:
name: sydney
london:
name: london
services:
sydney-service:
image: whatever
hostname: sydney-service
You connect them by placing them in the same network. That is the purpose of networks in docker and one of the prerequisites of connecting docker containers over docker networking.
You can have a container in more than one network, which may solve issues you are facing:
version: '3.7'
networks:
sydney:
name: sydney
london:
name: london
global:
services:
sydney-service:
image: whatever
hostname: sydney-service
container_name: sydney-service
networks:
- sydney
- global
london-service:
image: whatever
hostname: london-service
container_name: london-service
environment:
PAIR_SERVER: sydney-service:8080 # doesn't work
networks:
- london
- global
The other option is to bypass container networking, and communicate with the other service on a published port. In that case, the hostname is the docker host, and the port is the published port rather than the container port. I recommend against this if your purpose is to be able to communicate between containers deployed with a compose file.