From 0694c78c961d990e6e85607863a7fb99f72d288f Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 22 Mar 2018 19:11:43 -0400 Subject: [PATCH 1/4] Add .containerenv file This will allow programs to easily identify they are running in a container Signed-off-by: Matthew Heon --- libpod/container_internal.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 2ee2174db8..ddebc4bf99 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -672,6 +672,16 @@ func (c *Container) makeBindMounts() error { c.state.BindMounts["/etc/hostname"] = hostnamePath } + // Make .containerenv + if _, ok := c.state.BindMounts["/.containerenv"]; !ok { + // Empty string for now, but we may consider populating this later + containerenvPath, err := c.writeStringToRundir(".containerenv", "") + if err != nil { + return errors.Wrapf(err, "error creating containerenv file for container %s", c.ID()) + } + c.state.BindMounts["/.containerenv"] = containerenvPath + } + return nil } From 4d8fd903a44e2767635afbd02dacf2763fe9395e Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 23 Mar 2018 09:28:45 -0400 Subject: [PATCH 2/4] Document .containerenv in manpages. Move it to /run. Signed-off-by: Matthew Heon --- docs/podman-run.1.md | 8 ++++++++ libpod/container_internal.go | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/podman-run.1.md b/docs/podman-run.1.md index edd7ed681d..c1183e9101 100644 --- a/docs/podman-run.1.md +++ b/docs/podman-run.1.md @@ -21,6 +21,14 @@ If the IMAGE is not already loaded then **podman run** will pull the IMAGE, and all image dependencies, from the repository in the same way running **podman pull** IMAGE, before it starts the container from that image. +Several files will be automatically created within the container when it is run. +These include `/etc/hosts`, `/etc/hostname`, and `/etc/resolv.conf` to manage +networking. These will be based on the host's version of the files, though they +can be customized with options (for example, **--dns** will override the host's +DNS servers in the created `resolv.conf`). Additionally, an empty file is +created in each container to indicate to programs they are running in a +container. This file is located at `/run/.containerenv`. + ## OPTIONS **--add-host**=[] Add a custom host-to-IP mapping (host:ip) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index ddebc4bf99..8032424c43 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -673,13 +673,14 @@ func (c *Container) makeBindMounts() error { } // Make .containerenv - if _, ok := c.state.BindMounts["/.containerenv"]; !ok { + // Empty file, so no need to recreate if it exists + if _, ok := c.state.BindMounts["/run/.containerenv"]; !ok { // Empty string for now, but we may consider populating this later containerenvPath, err := c.writeStringToRundir(".containerenv", "") if err != nil { return errors.Wrapf(err, "error creating containerenv file for container %s", c.ID()) } - c.state.BindMounts["/.containerenv"] = containerenvPath + c.state.BindMounts["/run/.containerenv"] = containerenvPath } return nil From 281902735bf20c262f96131e360993bd3c2908ac Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 23 Mar 2018 10:19:51 -0400 Subject: [PATCH 3/4] Small manpage reword Signed-off-by: Matthew Heon --- docs/podman-run.1.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/podman-run.1.md b/docs/podman-run.1.md index c1183e9101..00085950bf 100644 --- a/docs/podman-run.1.md +++ b/docs/podman-run.1.md @@ -21,13 +21,13 @@ If the IMAGE is not already loaded then **podman run** will pull the IMAGE, and all image dependencies, from the repository in the same way running **podman pull** IMAGE, before it starts the container from that image. -Several files will be automatically created within the container when it is run. -These include `/etc/hosts`, `/etc/hostname`, and `/etc/resolv.conf` to manage -networking. These will be based on the host's version of the files, though they -can be customized with options (for example, **--dns** will override the host's -DNS servers in the created `resolv.conf`). Additionally, an empty file is -created in each container to indicate to programs they are running in a -container. This file is located at `/run/.containerenv`. +Several files will be automatically created within the container. These include +`/etc/hosts`, `/etc/hostname`, and `/etc/resolv.conf` to manage networking. +These will be based on the host's version of the files, though they can be +customized with options (for example, **--dns** will override the host's DNS +servers in the created `resolv.conf`). Additionally, an empty file is created in +each container to indicate to programs they are running in a container. This file +is located at `/run/.containerenv`. ## OPTIONS **--add-host**=[] From a21b575aaebf1c4ccd3232eb31a977ac23040183 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 23 Mar 2018 10:23:26 -0400 Subject: [PATCH 4/4] Add CONTAINER environment variable Signed-off-by: Matthew Heon --- libpod/container_internal.go | 1 + 1 file changed, 1 insertion(+) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 8032424c43..9ab928780f 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -909,6 +909,7 @@ func (c *Container) generateSpec() (*spec.Spec, error) { g.SetHostname(c.Hostname()) g.AddProcessEnv("HOSTNAME", g.Spec().Hostname) + g.AddProcessEnv("container", "libpod") return g.Spec(), nil }