You could use network_mode: "container:{name}"
instead of service:{name}
. See here https://docs.docker.com/reference/compose-file/services/#network_mode
Service definitions have to be defined in the same compose file or merged into one file at some point in order to be able to reference each other. Containers don't have that restriction.