In production, your database might not be running inside a Docker container, but it's useful to be able to represent it logically inside Compose as a service.
Compose should have a concept of "external" services, which specify a host/port and can be "linked" from other services. For example:
db:
type: external
host: 1.2.3.4
port: 5432
environment:
POSTGRES_USER: produser
POSTGRES_PASSWORD: prodpass
This results in services which link to this service being furnished with hostnames and environment variables in exactly the same way as if they were linked to a Docker container:
$ docker-compose run web cat /etc/hosts
127.0.0.1 localhost
1.2.3.4 db
$ docker-compose run web env
DB_PORT=tcp://1.2.3.4:5432
DB_PORT_5432_TCP=tcp://1.2.3.4:5432
DB_PORT_5432_TCP_ADDR=1.2.3.4
DB_PORT_5432_TCP_PORT=5432
DB_PORT_5432_TCP_PROTO=tcp
DB_ENV_POSTGRES_USER=produser
DB_ENV_POSTGRES_PASSWORD=prodpass
This was previously described in #988.
In production, your database might not be running inside a Docker container, but it's useful to be able to represent it logically inside Compose as a service.
Compose should have a concept of "external" services, which specify a host/port and can be "linked" from other services. For example:
This results in services which link to this service being furnished with hostnames and environment variables in exactly the same way as if they were linked to a Docker container:
This was previously described in #988.