summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/common.go3
-rw-r--r--cmd/podman/shared/create.go10
-rw-r--r--cmd/podman/shared/intermediate.go1
-rw-r--r--completions/bash/podman1
-rw-r--r--docs/podman-create.1.md23
-rw-r--r--docs/podman-run.1.md24
-rw-r--r--test/e2e/run_test.go16
7 files changed, 70 insertions, 8 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index 50f3d9a7b..96a1c2244 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -221,6 +221,9 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"env", "e", []string{},
"Set environment variables in container",
)
+ createFlags.Bool(
+ "env-host", false, "Use all current host environment variables in container",
+ )
createFlags.StringSlice(
"env-file", []string{},
"Read in a file of environment variables",
diff --git a/cmd/podman/shared/create.go b/cmd/podman/shared/create.go
index f401d3cf5..736a682eb 100644
--- a/cmd/podman/shared/create.go
+++ b/cmd/podman/shared/create.go
@@ -483,6 +483,16 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
// ENVIRONMENT VARIABLES
env := EnvVariablesFromData(data)
+ if c.Bool("env-host") {
+ for _, e := range os.Environ() {
+ pair := strings.SplitN(e, "=", 2)
+ if _, ok := env[pair[0]]; !ok {
+ if len(pair) > 1 {
+ env[pair[0]] = pair[1]
+ }
+ }
+ }
+ }
if err := parse.ReadKVStrings(env, c.StringSlice("env-file"), c.StringArray("env")); err != nil {
return nil, errors.Wrapf(err, "unable to process environment variables")
}
diff --git a/cmd/podman/shared/intermediate.go b/cmd/podman/shared/intermediate.go
index eecd1604c..855f84086 100644
--- a/cmd/podman/shared/intermediate.go
+++ b/cmd/podman/shared/intermediate.go
@@ -393,6 +393,7 @@ func NewIntermediateLayer(c *cliconfig.PodmanCommand, remote bool) GenericCLIRes
m["dns-search"] = newCRStringSlice(c, "dns-search")
m["entrypoint"] = newCRString(c, "entrypoint")
m["env"] = newCRStringArray(c, "env")
+ m["env-host"] = newCRBool(c, "env-host")
m["env-file"] = newCRStringSlice(c, "env-file")
m["expose"] = newCRStringSlice(c, "expose")
m["gidmap"] = newCRStringSlice(c, "gidmap")
diff --git a/completions/bash/podman b/completions/bash/podman
index 65c6308cc..2b9254d47 100644
--- a/completions/bash/podman
+++ b/completions/bash/podman
@@ -1740,6 +1740,7 @@ _podman_container_run() {
--dns-search
--entrypoint
--env -e
+ --env-host
--env-file
--expose
--gidmap
diff --git a/docs/podman-create.1.md b/docs/podman-create.1.md
index 9cf3e038d..00b706d4a 100644
--- a/docs/podman-create.1.md
+++ b/docs/podman-create.1.md
@@ -245,13 +245,15 @@ You need to specify multi option commands in the form of a json string.
Set environment variables
-This option allows you to specify arbitrary
-environment variables that are available for the process that will be launched
-inside of the container.
+This option allows you to specify arbitrary environment variables that are available for the process that will be launched inside of the container. If you specify a environment variable without a value, podman will check the host environment for a value or set the environment to "". See **Environment** note below for precedence.
+
+**--env-host**=*true|false*
+
+Use host environment inside of the container. See **Environment** note below for precedence.
**--env-file**=*file*
-Read in a line delimited file of environment variables
+Read in a line delimited file of environment variables. See **Environment** note below for precedence.
**--expose**=*port*
@@ -901,6 +903,19 @@ The fuse-overlay package provides a userspace overlay storage driver, otherwise
the vfs storage driver, which is diskspace expensive and does not perform well. slirp4netns is
required for VPN, without it containers need to be run with the --net=host flag.
+## ENVIRONMENT
+
+Environment variables within containers can be set using multiple different options: This section describes the presidence.
+
+Presidence Order:
+ **--env-host** : Host environment of the process executing podman is added.
+
+ Container image : Any enviroment variables specified in the contianer image.
+
+ **--env-file** : Any environment variables specfied via env-files. If multiple files specified, then they override each other in order of entry.
+
+ **--env** : Any environment variables specified will overide previous settings.
+
## FILES
**/etc/subuid**
diff --git a/docs/podman-run.1.md b/docs/podman-run.1.md
index 4889e5755..ea1670fac 100644
--- a/docs/podman-run.1.md
+++ b/docs/podman-run.1.md
@@ -252,13 +252,15 @@ You need to specify multi option commands in the form of a json string.
Set environment variables
-This option allows you to specify arbitrary
-environment variables that are available for the process that will be launched
-inside of the container.
+This option allows you to specify arbitrary environment variables that are available for the process that will be launched inside of the container. If you specify a environment variable without a value, podman will check the host environment for a value or set the environment to "". See **Environment** note below for precedence.
+
+**--env-host**=*true|false*
+
+Use host environment inside of the container. See **Environment** note below for precedence.
**--env-file**=*file*
-Read in a line delimited file of environment variables
+Read in a line delimited file of environment variables. See **Environment** note below for precedence.
**--expose**=*port*
@@ -1185,6 +1187,20 @@ The fuse-overlay package provides a userspace overlay storage driver, otherwise
the vfs storage driver, which is diskspace expensive and does not perform well. slirp4netns is
required for VPN, without it containers need to be run with the --net=host flag.
+## ENVIRONMENT
+
+Environment variables within containers can be set using multiple different options: This section describes the presidence.
+
+Presidence Order:
+
+ **--env-host** : Host environment of the process executing podman is added.
+
+ Container image : Any enviroment variables specified in the contianer image.
+
+ **--env-file** : Any environment variables specfied via env-files. If multiple files specified, then they override each other in order of entry.
+
+ **--env** : Any environment variables specified will overide previous settings.
+
## FILES
**/etc/subuid**
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index 3fc628589..623e08c2a 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -224,6 +224,22 @@ var _ = Describe("Podman run", func() {
Expect(match).Should(BeTrue())
})
+ It("podman run --host-env environment test", func() {
+ os.Setenv("FOO", "BAR")
+ session := podmanTest.Podman([]string{"run", "--rm", "--env-host", ALPINE, "printenv", "FOO"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ match, _ := session.GrepString("BAR")
+ Expect(match).Should(BeTrue())
+
+ session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO=BAR1", "--env-host", ALPINE, "printenv", "FOO"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ match, _ = session.GrepString("BAR1")
+ Expect(match).Should(BeTrue())
+ os.Unsetenv("FOO")
+ })
+
It("podman run limits test", func() {
SkipIfRootless()
session := podmanTest.Podman([]string{"run", "--rm", "--ulimit", "rtprio=99", "--cap-add=sys_nice", fedoraMinimal, "cat", "/proc/self/sched"})