Update documentation for links

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2016-01-21 13:55:54 +00:00
parent 9a3378930f
commit 2f41f3aa7e
3 changed files with 53 additions and 26 deletions

View File

@ -318,6 +318,10 @@ container name and the link alias (`CONTAINER:ALIAS`).
- project_db_1:mysql - project_db_1:mysql
- project_db_1:postgresql - project_db_1:postgresql
> **Note:** If you're using the [version 2 file format](#version-2), the
> externally-created containers must be connected to at least one of the same
> networks as the service which is linking to them.
### extra_hosts ### extra_hosts
Add hostname mappings. Use the same values as the docker client `--add-host` parameter. Add hostname mappings. Use the same values as the docker client `--add-host` parameter.
@ -358,27 +362,24 @@ It's recommended that you use reverse-DNS notation to prevent your labels from c
### links ### links
> [Version 1 file format](#version-1) only. In version 2 files, use
> [networking](networking.md) for communication between containers.
Link to containers in another service. Either specify both the service name and Link to containers in another service. Either specify both the service name and
the link alias (`SERVICE:ALIAS`), or just the service name (which will also be a link alias (`SERVICE:ALIAS`), or just the service name.
used for the alias).
links: web:
- db links:
- db:database - db
- redis - db:database
- redis
An entry with the alias' name will be created in `/etc/hosts` inside containers Containers for the linked service will be reachable at a hostname identical to
for this service, e.g: the alias, or the service name if no alias was specified.
172.17.2.186 db Links also express dependency between services in the same way as
172.17.2.186 database [depends_on](#depends-on), so they determine the order of service startup.
172.17.2.187 redis
Environment variables will also be created - see the [environment variable > **Note:** If you define both links and [networks](#networks), services with
reference](env.md) for details. > links between them must share at least one network in common in order to
> communicate.
### logging ### logging
@ -862,7 +863,6 @@ In the majority of cases, moving from version 1 to 2 is a very simple process:
1. Indent the whole file by one level and put a `services:` key at the top. 1. Indent the whole file by one level and put a `services:` key at the top.
2. Add a `version: 2` line at the top of the file. 2. Add a `version: 2` line at the top of the file.
3. Delete all `links` entries.
It's more complicated if you're using particular configuration features: It's more complicated if you're using particular configuration features:
@ -879,14 +879,28 @@ It's more complicated if you're using particular configuration features:
options: options:
syslog-address: "tcp://192.168.0.42:123" syslog-address: "tcp://192.168.0.42:123"
- `links` with aliases: If you've defined a link with an alias such as - `links` with environment variables: As documented in the
`myservice:db`, there's currently no equivalent to this in version 2. You [environment variables reference](env.md), environment variables created by
will have to refer to the service using its name (in this example, links have been deprecated for some time. In the new Docker network system,
`myservice`). they have been removed. You should either connect directly to the
appropriate hostname or set the relevant environment variable yourself,
using the link hostname:
- `external_links`: Links are deprecated, so you should use web:
[external networks](networking.md#using-externally-created-networks) to links:
communicate with containers outside the app. - db
environment:
- DB_PORT=tcp://db:5432
- `external_links`: Compose uses Docker networks when running version 2
projects, so links behave slightly differently. In particular, two
containers must be connected to at least one network in common in order to
communicate, even if explicitly linked together.
Either connect the external container to your app's
[default network](networking.md), or connect both the external container and
your service's containers to an
[external network](networking.md#using-a-pre-existing-network).
- `net`: If you're using `host`, `bridge` or `none`, this is now replaced by - `net`: If you're using `host`, `bridge` or `none`, this is now replaced by
`networks`: `networks`:

View File

@ -11,7 +11,9 @@ weight=3
# Compose environment variables reference # Compose environment variables reference
**Note:** Environment variables are no longer the recommended method for connecting to linked services. Instead, you should use the link name (by default, the name of the linked service) as the hostname to connect to. See the [docker-compose.yml documentation](compose-file.md#links) for details. > **Note:** Environment variables are no longer the recommended method for connecting to linked services. Instead, you should use the link name (by default, the name of the linked service) as the hostname to connect to. See the [docker-compose.yml documentation](compose-file.md#links) for details.
>
> Environment variables will only be populated if you're using the [legacy version 1 Compose file format](compose-file.md#versioning).
Compose uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container. Compose uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container.

View File

@ -57,7 +57,18 @@ If any containers have connections open to the old container, they will be close
## Links ## Links
Docker links are a one-way, single-host communication system. They should now be considered deprecated, and as part of upgrading your app to the v2 format, you must remove any `links` sections from your `docker-compose.yml` and use service names (e.g. `web`, `db`) as the hostnames to connect to. Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate - by default, any service can reach any other service at that service's name. In the following example, `db` is reachable from `web` at the hostnames `db` and `database`:
version: 2
services:
web:
build: .
links:
- "db:database"
db:
image: postgres
See the [links reference](compose-file.md#links) for more information.
## Multi-host networking ## Multi-host networking