mirror of https://github.com/docker/docs.git
Better variable substitution example
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
85e2fb63b3
commit
3034803258
|
@ -1089,21 +1089,24 @@ It's more complicated if you're using particular configuration features:
|
||||||
## Variable substitution
|
## Variable substitution
|
||||||
|
|
||||||
Your configuration options can contain environment variables. Compose uses the
|
Your configuration options can contain environment variables. Compose uses the
|
||||||
variable values from the shell environment in which `docker-compose` is run. For
|
variable values from the shell environment in which `docker-compose` is run.
|
||||||
example, suppose the shell contains `POSTGRES_VERSION=9.3` and you supply this
|
For example, suppose the shell contains `EXTERNAL_PORT=8000` and you supply
|
||||||
configuration:
|
this configuration:
|
||||||
|
|
||||||
db:
|
web:
|
||||||
image: "postgres:${POSTGRES_VERSION}"
|
build: .
|
||||||
|
ports:
|
||||||
|
- "${EXTERNAL_PORT}:5000"
|
||||||
|
|
||||||
When you run `docker-compose up` with this configuration, Compose looks for the
|
When you run `docker-compose up` with this configuration, Compose looks for
|
||||||
`POSTGRES_VERSION` environment variable in the shell and substitutes its value
|
the `EXTERNAL_PORT` environment variable in the shell and substitutes its
|
||||||
in. For this example, Compose resolves the `image` to `postgres:9.3` before
|
value in. In this example, Compose resolves the port mapping to `"8000:5000"`
|
||||||
running the configuration.
|
before creating the `web` container.
|
||||||
|
|
||||||
If an environment variable is not set, Compose substitutes with an empty
|
If an environment variable is not set, Compose substitutes with an empty
|
||||||
string. In the example above, if `POSTGRES_VERSION` is not set, the value for
|
string. In the example above, if `EXTERNAL_PORT` is not set, the value for the
|
||||||
the `image` option is `postgres:`.
|
port mapping is `:5000` (which is of course an invalid port mapping, and will
|
||||||
|
result in an error when attempting to create the container).
|
||||||
|
|
||||||
Both `$VARIABLE` and `${VARIABLE}` syntax are supported. Extended shell-style
|
Both `$VARIABLE` and `${VARIABLE}` syntax are supported. Extended shell-style
|
||||||
features, such as `${VARIABLE-default}` and `${VARIABLE/foo/bar}`, are not
|
features, such as `${VARIABLE-default}` and `${VARIABLE/foo/bar}`, are not
|
||||||
|
|
Loading…
Reference in New Issue