Merge pull request #3249 from aanand/better-env-substitution-example
Better variable substitution example
(cherry picked from commit a63a05964b)
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
parent
888d2f3756
commit
e15c2d53df
1 changed files with 14 additions and 11 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue