mirror of https://github.com/docker/docs.git
added support for setting environment variables in docker engines
Signed-off-by: Ryan Grothouse <rgrothouse@gmail.com>
This commit is contained in:
parent
2c36635dd4
commit
d553a2c757
|
@ -196,6 +196,11 @@ var sharedCreateFlags = []cli.Flag{
|
||||||
Name: "engine-storage-driver",
|
Name: "engine-storage-driver",
|
||||||
Usage: "Specify a storage driver to use with the engine",
|
Usage: "Specify a storage driver to use with the engine",
|
||||||
},
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "engine-env",
|
||||||
|
Usage: "Specify environment variables to set in the engine",
|
||||||
|
Value: &cli.StringSlice{},
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "swarm",
|
Name: "swarm",
|
||||||
Usage: "Configure Machine with Swarm",
|
Usage: "Configure Machine with Swarm",
|
||||||
|
|
|
@ -70,6 +70,7 @@ func cmdCreate(c *cli.Context) {
|
||||||
},
|
},
|
||||||
EngineOptions: &engine.EngineOptions{
|
EngineOptions: &engine.EngineOptions{
|
||||||
ArbitraryFlags: c.StringSlice("engine-opt"),
|
ArbitraryFlags: c.StringSlice("engine-opt"),
|
||||||
|
Env: c.StringSlice("engine-env"),
|
||||||
InsecureRegistry: c.StringSlice("engine-insecure-registry"),
|
InsecureRegistry: c.StringSlice("engine-insecure-registry"),
|
||||||
Labels: c.StringSlice("engine-label"),
|
Labels: c.StringSlice("engine-label"),
|
||||||
RegistryMirror: c.StringSlice("engine-registry-mirror"),
|
RegistryMirror: c.StringSlice("engine-registry-mirror"),
|
||||||
|
|
|
@ -60,6 +60,7 @@ Options:
|
||||||
--engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option] Specify registry mirrors to use
|
--engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option] Specify registry mirrors to use
|
||||||
--engine-label [--engine-label option --engine-label option] Specify labels for the created engine
|
--engine-label [--engine-label option --engine-label option] Specify labels for the created engine
|
||||||
--engine-storage-driver "aufs" Specify a storage driver to use with the engine
|
--engine-storage-driver "aufs" Specify a storage driver to use with the engine
|
||||||
|
--engine-env Specify environment variables to set in the engine
|
||||||
--swarm Configure Machine with Swarm
|
--swarm Configure Machine with Swarm
|
||||||
--swarm-master Configure Machine to be a Swarm master
|
--swarm-master Configure Machine to be a Swarm master
|
||||||
--swarm-discovery Discovery service to use with Swarm
|
--swarm-discovery Discovery service to use with Swarm
|
||||||
|
@ -146,6 +147,17 @@ $ docker-machine create -d virtualbox \
|
||||||
gdns
|
gdns
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Additionally, Docker Machine supports a flag, `--engine-env`, which can be used to
|
||||||
|
specify arbitrary environment variables to be set within the engine with the syntax `--engine-env name=value`. For example, to specify that the engine should use `example.com` as the proxy server, you could run the following create command:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker-machine create -d virtualbox \
|
||||||
|
--engine-env HTTP_PROXY=http://example.com:8080 \
|
||||||
|
--engine-env HTTPS_PROXY=https://example.com:8080 \
|
||||||
|
--engine-env NO_PROXY=example2.com \
|
||||||
|
proxbox
|
||||||
|
```
|
||||||
|
|
||||||
## Specifying Docker Swarm options for the created machine
|
## Specifying Docker Swarm options for the created machine
|
||||||
|
|
||||||
In addition to being able to configure Docker Engine options as listed above,
|
In addition to being able to configure Docker Engine options as listed above,
|
||||||
|
|
|
@ -4,6 +4,7 @@ type EngineOptions struct {
|
||||||
ArbitraryFlags []string
|
ArbitraryFlags []string
|
||||||
Dns []string
|
Dns []string
|
||||||
GraphDir string
|
GraphDir string
|
||||||
|
Env []string
|
||||||
Ipv6 bool
|
Ipv6 bool
|
||||||
InsecureRegistry []string
|
InsecureRegistry []string
|
||||||
Labels []string
|
Labels []string
|
||||||
|
|
|
@ -140,6 +140,9 @@ DOCKER_STORAGE={{.EngineOptions.StorageDriver}}
|
||||||
DOCKER_TLS=auto
|
DOCKER_TLS=auto
|
||||||
SERVERKEY={{.AuthOptions.ServerKeyRemotePath}}
|
SERVERKEY={{.AuthOptions.ServerKeyRemotePath}}
|
||||||
SERVERCERT={{.AuthOptions.ServerCertRemotePath}}
|
SERVERCERT={{.AuthOptions.ServerCertRemotePath}}
|
||||||
|
|
||||||
|
{{range .EngineOptions.Env}}export \"{{ printf "%q" . }}\"
|
||||||
|
{{end}}
|
||||||
`
|
`
|
||||||
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -172,6 +172,7 @@ MountFlags=slave
|
||||||
LimitNOFILE=1048576
|
LimitNOFILE=1048576
|
||||||
LimitNPROC=1048576
|
LimitNPROC=1048576
|
||||||
LimitCORE=infinity
|
LimitCORE=infinity
|
||||||
|
Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}}
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -91,6 +91,8 @@ DOCKER_OPTS='
|
||||||
{{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}}
|
{{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
'
|
'
|
||||||
|
{{range .EngineOptions.Env}}export \"{{ printf "%q" . }}\"
|
||||||
|
{{end}}
|
||||||
`
|
`
|
||||||
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -246,6 +246,7 @@ MountFlags=slave
|
||||||
LimitNOFILE=1048576
|
LimitNOFILE=1048576
|
||||||
LimitNPROC=1048576
|
LimitNPROC=1048576
|
||||||
LimitCORE=infinity
|
LimitCORE=infinity
|
||||||
|
Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}}
|
||||||
`
|
`
|
||||||
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -164,7 +164,7 @@ func ConfigureAuth(p Provisioner) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = p.SSHCommand(fmt.Sprintf("printf \"%s\" | sudo tee %s", dkrcfg.EngineOptions, dkrcfg.EngineOptionsPath)); err != nil {
|
if _, err = p.SSHCommand(fmt.Sprintf("printf %%s \"%s\" | sudo tee %s", dkrcfg.EngineOptions, dkrcfg.EngineOptionsPath)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load ${BASE_TEST_DIR}/helpers.bash
|
||||||
|
|
||||||
|
|
||||||
|
@test "$DRIVER: create with arbitrary engine envs" {
|
||||||
|
|
||||||
|
run machine create -d $DRIVER \
|
||||||
|
--engine-env=TEST=VALUE \
|
||||||
|
$NAME
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "$DRIVER: test docker process envs" {
|
||||||
|
|
||||||
|
# get pid of docker process, check process envs for set Environment Variable from above test
|
||||||
|
run machine ssh $NAME 'pgrep -f "docker -d" | xargs -I % sudo cat /proc/%/environ | grep -q "TEST=VALUE"'
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
}
|
Loading…
Reference in New Issue