diff --git a/compose/compose-file/compose-file-v1.md b/compose/compose-file/compose-file-v1.md index 9910f6190e..c68244856f 100644 --- a/compose/compose-file/compose-file-v1.md +++ b/compose/compose-file/compose-file-v1.md @@ -1,8 +1,6 @@ --- description: Compose file reference keywords: fig, composition, compose version 1, docker -redirect_from: -- /compose/yml title: Compose file version 1 reference toc_max: 4 toc_min: 1 @@ -442,6 +440,46 @@ Links also express dependency between services in the same way as > links between them must share at least one network in common in order to > communicate. +#### link environment variables + +> [Version 1 file format](compose-versioning.md#version-1) only. In version 2 and +> up, custom networks are used, and no environment variables are created. + +> **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. Refer to the +> [docker-compose.yml documentation](compose-file/index.md#links) for details. +> +> Environment variables are only populated if you use the +> [legacy version 1 Compose file format](compose-file/compose-versioning.md#versioning). +{: .warning } + +Compose uses [Docker links](../../network/links.md) +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. + +To see what environment variables are available to a service, run `docker-compose run SERVICE env`. + +name\_PORT
+Full URL, such as `DB_PORT=tcp://172.17.0.5:5432` + +name\_PORT\_num\_protocol
+Full URL, such as `DB_PORT_5432_TCP=tcp://172.17.0.5:5432` + +name\_PORT\_num\_protocol\_ADDR
+Container's IP address, such as `DB_PORT_5432_TCP_ADDR=172.17.0.5` + +name\_PORT\_num\_protocol\_PORT
+Exposed port number, such as `DB_PORT_5432_TCP_PORT=5432` + +name\_PORT\_num\_protocol\_PROTO
+Protocol (tcp or udp), such as `DB_PORT_5432_TCP_PROTO=tcp` + +name\_NAME
+Fully qualified container name, such as `DB_1_NAME=/myapp_web_1/myapp_db_1` + ### log_driver > [Version 1 file format](compose-versioning.md#version-1) only. In version 2 and up, use diff --git a/compose/compose-file/compose-file-v2.md b/compose/compose-file/compose-file-v2.md index ad39219bee..8963e89f32 100644 --- a/compose/compose-file/compose-file-v2.md +++ b/compose/compose-file/compose-file-v2.md @@ -1,8 +1,6 @@ --- description: Compose file reference keywords: fig, composition, compose version 3, docker -redirect_from: -- /compose/yml title: Compose file version 2 reference toc_max: 4 toc_min: 1 diff --git a/compose/compose-file/compose-versioning.md b/compose/compose-file/compose-versioning.md index 575ad681b9..d7f7eba3bf 100644 --- a/compose/compose-file/compose-versioning.md +++ b/compose/compose-file/compose-versioning.md @@ -453,10 +453,8 @@ It's more complicated if you're using particular configuration features: options: syslog-address: "tcp://192.168.0.42:123" -- `links` with environment variables: As documented in the - [environment variables reference](../link-env-deprecated.md), environment variables - created by - links have been deprecated for some time. In the new Docker network system, +- `links` with environment variables: environment variables created by + links, such as `CONTAINERNAME_PORT`, ` have been deprecated for some time. In the new Docker network system, they have been removed. You should either connect directly to the appropriate hostname or set the relevant environment variable yourself, using the link hostname: diff --git a/compose/environment-variables.md b/compose/environment-variables.md index 8403a42af9..7166d288be 100644 --- a/compose/environment-variables.md +++ b/compose/environment-variables.md @@ -2,6 +2,9 @@ title: Environment variables in Compose description: How to set, use and manage environment variables in Compose keywords: compose, orchestration, environment, env file +redirect_from: +- /compose/env +- /compose/link-env-deprecated --- There are multiple parts of Compose that deal with environment variables in one @@ -192,8 +195,6 @@ documented in [CLI Environment Variables](reference/envvars.md). ## Environment variables created by links When using the ['links' option](compose-file/index.md#links) in a -[v1 Compose file](compose-file/index.md#version-1), environment variables are created -for each link. They are documented in -the [Link environment variables reference](link-env-deprecated.md). - -However, these variables are deprecated. Use the link alias as a hostname instead. +[v1 Compose file](compose-file/compose-file-v1.md#link-environment-variables), +environment variables are created for each link. These variables are deprecated. +Use the link alias as a hostname instead. diff --git a/compose/link-env-deprecated.md b/compose/link-env-deprecated.md deleted file mode 100644 index d4b5095e37..0000000000 --- a/compose/link-env-deprecated.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -description: Compose CLI reference -keywords: fig, composition, compose, docker, orchestration, cli, reference -redirect_from: -- /compose/env -title: Link environment variables (superseded) -notoc: true ---- - -> **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/#links) for details. -> -> Environment variables are only populated if you're using the [legacy version 1 Compose file format](compose-file/compose-versioning.md#versioning). - -Compose uses [Docker links](../network/links.md) -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. - -To see what environment variables are available to a service, run `docker-compose run SERVICE env`. - -name\_PORT
-Full URL, such as `DB_PORT=tcp://172.17.0.5:5432` - -name\_PORT\_num\_protocol
-Full URL, such as `DB_PORT_5432_TCP=tcp://172.17.0.5:5432` - -name\_PORT\_num\_protocol\_ADDR
-Container's IP address, such as `DB_PORT_5432_TCP_ADDR=172.17.0.5` - -name\_PORT\_num\_protocol\_PORT
-Exposed port number, such as `DB_PORT_5432_TCP_PORT=5432` - -name\_PORT\_num\_protocol\_PROTO
-Protocol (tcp or udp), such as `DB_PORT_5432_TCP_PROTO=tcp` - -name\_NAME
-Fully qualified container name, such as `DB_1_NAME=/myapp_web_1/myapp_db_1` - -## Related information - -- [User guide](index.md) -- [Installing Compose](install.md) -- [Getting Started](gettingstarted.md) -- [Command line reference](reference/index.md) -- [Compose file reference](compose-file/index.md) -- [Sample apps with Compose](samples-for-compose.md)