Clean docker run -e
reference docs
Simplified the docs on how to set environment variables in a container. Makes it clear that you have three options, and how to use them. Signed-off-by: Joao Fernandes <joao.fernandes@docker.com>
This commit is contained in:
parent
71b0f91129
commit
66cfdff646
@ -365,75 +365,46 @@ system's interfaces.
|
|||||||
$ docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
|
$ docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
|
||||||
```
|
```
|
||||||
|
|
||||||
This sets simple (non-array) environmental variables in the container. For
|
Use the `-e`, `--env`, and `--env-file` flags to set simple (non-array)
|
||||||
illustration all three
|
environment variables in the container you're running, or overwrite variables
|
||||||
flags are shown here. Where `-e`, `--env` take an environment variable and
|
that are defined in the Dockerfile of the image you're running.
|
||||||
value, or if no `=` is provided, then that variable's current value, set via
|
|
||||||
`export`, is passed through (i.e. `$MYVAR1` from the host is set to `$MYVAR1`
|
|
||||||
in the container). When no `=` is provided and that variable is not defined
|
|
||||||
in the client's environment then that variable will be removed from the
|
|
||||||
container's list of environment variables. All three flags, `-e`, `--env` and
|
|
||||||
`--env-file` can be repeated.
|
|
||||||
|
|
||||||
Regardless of the order of these three flags, the `--env-file` are processed
|
You can define the variable and its value when running the container:
|
||||||
first, and then `-e`, `--env` flags. This way, the `-e` or `--env` will
|
|
||||||
override variables as needed.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cat ./env.list
|
$ docker run --env VAR1=value1 --env VAR2=value2 ubuntu env | grep VAR
|
||||||
TEST_FOO=BAR
|
VAR1=value1
|
||||||
$ docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO
|
VAR2=value2
|
||||||
TEST_FOO=This is a test
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `--env-file` flag takes a filename as an argument and expects each line
|
You can also use variables that you've exported to your local environment:
|
||||||
to be in the `VAR=VAL` format, mimicking the argument passed to `--env`. Comment
|
|
||||||
lines need only be prefixed with `#`
|
|
||||||
|
|
||||||
An example of a file passed with `--env-file`
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cat ./env.list
|
export VAR1=value1
|
||||||
TEST_FOO=BAR
|
export VAR2=value2
|
||||||
|
|
||||||
# this is a comment
|
$ docker run --env VAR1 --env VAR2 ubuntu env | grep VAR
|
||||||
TEST_APP_DEST_HOST=10.10.0.127
|
VAR1=value1
|
||||||
TEST_APP_DEST_PORT=8888
|
VAR2=value2
|
||||||
_TEST_BAR=FOO
|
```
|
||||||
TEST_APP_42=magic
|
|
||||||
helloWorld=true
|
|
||||||
123qwe=bar
|
|
||||||
org.spring.config=something
|
|
||||||
|
|
||||||
# pass through this variable from the caller
|
When running the command, the Docker CLI client checks the value the variable
|
||||||
TEST_PASSTHROUGH
|
has in your local environment and passes it to the container.
|
||||||
$ TEST_PASSTHROUGH=howdy docker run --env-file ./env.list busybox env
|
If no `=` is provided and that variable is not exported in your local
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
environment, the variable won't be set in the container.
|
||||||
HOSTNAME=5198e0745561
|
|
||||||
TEST_FOO=BAR
|
|
||||||
TEST_APP_DEST_HOST=10.10.0.127
|
|
||||||
TEST_APP_DEST_PORT=8888
|
|
||||||
_TEST_BAR=FOO
|
|
||||||
TEST_APP_42=magic
|
|
||||||
helloWorld=true
|
|
||||||
TEST_PASSTHROUGH=howdy
|
|
||||||
HOME=/root
|
|
||||||
123qwe=bar
|
|
||||||
org.spring.config=something
|
|
||||||
|
|
||||||
$ docker run --env-file ./env.list busybox env
|
You can also load the environment variables from a file. This file should use
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
the syntax `<variable>= value`, and `#` for comments.
|
||||||
HOSTNAME=5198e0745561
|
|
||||||
TEST_FOO=BAR
|
```bash
|
||||||
TEST_APP_DEST_HOST=10.10.0.127
|
$ cat env.list
|
||||||
TEST_APP_DEST_PORT=8888
|
# This is a comment
|
||||||
_TEST_BAR=FOO
|
VAR1=value1
|
||||||
TEST_APP_42=magic
|
VAR2=value2
|
||||||
helloWorld=true
|
|
||||||
TEST_PASSTHROUGH=
|
$ docker run --env-file env.list ubuntu env | grep VAR
|
||||||
HOME=/root
|
VAR1=value1
|
||||||
123qwe=bar
|
VAR2=value2
|
||||||
org.spring.config=something
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set metadata on container (-l, --label, --label-file)
|
### Set metadata on container (-l, --label, --label-file)
|
||||||
@ -615,11 +586,11 @@ Use Docker's `--restart` to specify a container's *restart policy*. A restart
|
|||||||
policy controls whether the Docker daemon restarts a container after exit.
|
policy controls whether the Docker daemon restarts a container after exit.
|
||||||
Docker supports the following restart policies:
|
Docker supports the following restart policies:
|
||||||
|
|
||||||
| Policy | Result |
|
| Policy | Result |
|
||||||
|-------------------|-----------------------------------------|
|
|:----------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `no` | Do not automatically restart the container when it exits. This is the default. |
|
| `no` | Do not automatically restart the container when it exits. This is the default. |
|
||||||
| `failure` | Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts. |
|
| `failure` | Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts. |
|
||||||
| `always` | Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container. |
|
| `always` | Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container. |
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker run --restart=always redis
|
$ docker run --restart=always redis
|
||||||
@ -744,7 +715,7 @@ On Windows, `--isolation` can take one of these values:
|
|||||||
|
|
||||||
|
|
||||||
| Value | Description |
|
| Value | Description |
|
||||||
|-----------|--------------------------------------------------------------------------------------------|
|
|:----------|:-------------------------------------------------------------------------------------------|
|
||||||
| `default` | Use the value specified by the Docker daemon's `--exec-opt` or system default (see below). |
|
| `default` | Use the value specified by the Docker daemon's `--exec-opt` or system default (see below). |
|
||||||
| `process` | Shared-kernel namespace isolation (not supported on Windows client operating systems). |
|
| `process` | Shared-kernel namespace isolation (not supported on Windows client operating systems). |
|
||||||
| `hyperv` | Hyper-V hypervisor partition-based isolation. |
|
| `hyperv` | Hyper-V hypervisor partition-based isolation. |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user