mirror of https://github.com/docker/compose.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
|
||||
|
||||
Your configuration options can contain environment variables. Compose uses the
|
||||
variable values from the shell environment in which `docker-compose` is run. For
|
||||
example, suppose the shell contains `POSTGRES_VERSION=9.3` and you supply this
|
||||
configuration:
|
||||
variable values from the shell environment in which `docker-compose` is run.
|
||||
For example, suppose the shell contains `EXTERNAL_PORT=8000` and you supply
|
||||
this configuration:
|
||||
|
||||
db:
|
||||
image: "postgres:${POSTGRES_VERSION}"
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "${EXTERNAL_PORT}:5000"
|
||||
|
||||
When you run `docker-compose up` with this configuration, Compose looks for the
|
||||
`POSTGRES_VERSION` environment variable in the shell and substitutes its value
|
||||
in. For this example, Compose resolves the `image` to `postgres:9.3` before
|
||||
running the configuration.
|
||||
When you run `docker-compose up` with this configuration, Compose looks for
|
||||
the `EXTERNAL_PORT` environment variable in the shell and substitutes its
|
||||
value in. In this example, Compose resolves the port mapping to `"8000:5000"`
|
||||
before creating the `web` container.
|
||||
|
||||
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
|
||||
the `image` option is `postgres:`.
|
||||
string. In the example above, if `EXTERNAL_PORT` is not set, the value for the
|
||||
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
|
||||
features, such as `${VARIABLE-default}` and `${VARIABLE/foo/bar}`, are not
|
||||
|
|
Loading…
Reference in New Issue