Skip to content

Link to a service which isn't a Docker container #1110

@aanand

Description

@aanand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions