diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2017-12-18 12:05:06 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-03 12:38:18 +0000 |
commit | 00d38cb37958f3c636aa5837b8f01dfad891a0b5 (patch) | |
tree | e0eb9039266a725f5315ac05f3909f7a6a4a309e /libpod/container.go | |
parent | 8aeb38e4a718925a78606b8aa014bce6b4a4054c (diff) | |
download | podman-00d38cb37958f3c636aa5837b8f01dfad891a0b5.tar.gz podman-00d38cb37958f3c636aa5837b8f01dfad891a0b5.tar.bz2 podman-00d38cb37958f3c636aa5837b8f01dfad891a0b5.zip |
podman create/run need to load information from the image
We should be pulling information out of the image to set the
defaults to use when setting up the container.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Closes: #110
Approved by: mheon
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/libpod/container.go b/libpod/container.go index 454fe43ac..18f3ca5ae 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -28,6 +28,7 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod/driver" crioAnnotations "github.com/projectatomic/libpod/pkg/annotations" + "github.com/projectatomic/libpod/pkg/chrootuser" "github.com/sirupsen/logrus" "github.com/ulule/deepcopier" "golang.org/x/sys/unix" @@ -153,7 +154,8 @@ type ContainerConfig struct { SharedNamespaceMap map[string]string `json:"sharedNamespaces"` // Time container was created CreatedTime time.Time `json:"createdTime"` - + // User/GID to use within the container + User string `json:"user"` // TODO save log location here and pass into OCI code // TODO allow overriding of log path } @@ -440,7 +442,6 @@ func newContainer(rspec *spec.Spec, lockDir string) (*Container, error) { ctr.config.Spec = new(spec.Spec) deepcopier.Copy(rspec).To(ctr.config.Spec) - ctr.config.CreatedTime = time.Now() // Path our lock file will reside at @@ -614,6 +615,20 @@ func (c *Container) Init() (err error) { g.AddBindMount(runDirResolv, "/etc/resolv.conf", []string{"rw"}) // Bind mount hosts g.AddBindMount(runDirHosts, "/etc/hosts", []string{"rw"}) + + if c.config.User != "" { + if !c.state.Mounted { + return errors.Wrapf(ErrCtrStateInvalid, "container %s must be mounted in order to translate User field", c.ID()) + } + uid, gid, err := chrootuser.GetUser(c.state.Mountpoint, c.config.User) + if err != nil { + return err + } + // User and Group must go together + g.SetProcessUID(uid) + g.SetProcessGID(gid) + } + c.runningSpec = g.Spec() c.runningSpec.Root.Path = c.state.Mountpoint c.runningSpec.Annotations[crioAnnotations.Created] = c.config.CreatedTime.Format(time.RFC3339Nano) @@ -1078,7 +1093,7 @@ func (c *Container) mountStorage() (err error) { } } - mountPoint, err := c.runtime.storageService.StartContainer(c.ID()) + mountPoint, err := c.runtime.storageService.MountContainerImage(c.ID()) if err != nil { return errors.Wrapf(err, "error mounting storage for container %s", c.ID()) } @@ -1124,7 +1139,7 @@ func (c *Container) cleanupStorage() error { } // Also unmount storage - if err := c.runtime.storageService.StopContainer(c.ID()); err != nil { + if err := c.runtime.storageService.UnmountContainerImage(c.ID()); err != nil { return errors.Wrapf(err, "error unmounting container %s root filesystem", c.ID()) } |