diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-12-04 11:56:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-04 11:56:24 -0500 |
commit | f01630acf35a11aecdbfb9b77b249dcec85e67b5 (patch) | |
tree | 05e8ea3a882fa97027b2dffc9a7005438919faca /libpod | |
parent | a2d536e59762f657ea573e809d1e6f79a89ba0a9 (diff) | |
parent | d9154e97ebad33ead3d7f0d6aa8dea2bc4374ac2 (diff) | |
download | podman-f01630acf35a11aecdbfb9b77b249dcec85e67b5.tar.gz podman-f01630acf35a11aecdbfb9b77b249dcec85e67b5.tar.bz2 podman-f01630acf35a11aecdbfb9b77b249dcec85e67b5.zip |
Merge pull request #8476 from rhatdan/containerenv
Add containerenv information to /run/.containerenv
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal_linux.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 9a417d75e..72eaeac8e 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -35,6 +35,7 @@ import ( "github.com/containers/podman/v2/pkg/rootless" "github.com/containers/podman/v2/pkg/util" "github.com/containers/podman/v2/utils" + "github.com/containers/podman/v2/version" "github.com/containers/storage/pkg/archive" "github.com/containers/storage/pkg/idtools" securejoin "github.com/cyphar/filepath-securejoin" @@ -1423,11 +1424,26 @@ func (c *Container) makeBindMounts() error { } } - // Make .containerenv - // Empty file, so no need to recreate if it exists + // Make .containerenv if it does not exist if _, ok := c.state.BindMounts["/run/.containerenv"]; !ok { - // Empty string for now, but we may consider populating this later - containerenvPath, err := c.writeStringToRundir(".containerenv", "") + var containerenv string + isRootless := 0 + if rootless.IsRootless() { + isRootless = 1 + } + imageID, imageName := c.Image() + + if c.Privileged() { + // Populate the .containerenv with container information + containerenv = fmt.Sprintf(`engine="podman-%s" +name=%q +id=%q +image=%q +imageid=%q +rootless=%d +`, version.Version.String(), c.Name(), c.ID(), imageName, imageID, isRootless) + } + containerenvPath, err := c.writeStringToRundir(".containerenv", containerenv) if err != nil { return errors.Wrapf(err, "error creating containerenv file for container %s", c.ID()) } |