You can also create a docker network outside of your docker:
docker network create my-shared-network
And in your docker-compose.yml:
version: '2' services: pg: image: postgres:9.4.4 container_name: pg expose: - "5432" networks: default: external: name: my-shared-network
And in your second docker-compose.yml:
version: '2' myapp: image: quay.io/myco/myapp container_name: myapp environment: DATABASE_URL: "http://pg:5432" net: ${NETWORK} expose: - "3000" networks: default: external: name: my-shared-network
And both instances will be able to see each other, without open ports on the host, you just need to set the ports, and there they will see each other through the network: "my-shared-network".
source share