diff options
author | umohnani8 <umohnani@redhat.com> | 2017-12-15 16:14:52 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-12-20 10:08:17 +0000 |
commit | 26a6e0de46f6fcc6c80a20068d0019b45465a28d (patch) | |
tree | bca94ecf461f0fedce13d0ebe4b26f76d7f8f6fb /libpod/container.go | |
parent | 5da9fd4953ae4c0806fab2fbcee5767fe7b57467 (diff) | |
download | podman-26a6e0de46f6fcc6c80a20068d0019b45465a28d.tar.gz podman-26a6e0de46f6fcc6c80a20068d0019b45465a28d.tar.bz2 podman-26a6e0de46f6fcc6c80a20068d0019b45465a28d.zip |
Add podman commit command
podman commit allows the user to commit containers
as images with options of tagging th image, setting
a commit message, setting the auther, and making
changes to the instructions.
Signed-off-by: umohnani8 <umohnani@redhat.com>
Closes: #143
Approved by: rhatdan
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/libpod/container.go b/libpod/container.go index 15ad1f49a..dc22c9c61 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -890,6 +890,10 @@ func (c *Container) Export(path string) error { return err } + return c.export(path) +} + +func (c *Container) export(path string) error { mountPoint := c.state.Mountpoint if !c.state.Mounted { mount, err := c.runtime.store.Mount(c.ID(), c.config.MountLabel) @@ -965,8 +969,36 @@ func (c *Container) Inspect(size bool) (*ContainerInspectData, error) { // Commit commits the changes between a container and its image, creating a new // image -func (c *Container) Commit() (*storage.Image, error) { - return nil, ErrNotImplemented +func (c *Container) Commit(pause bool, options CopyOptions) error { + c.lock.Lock() + defer c.lock.Unlock() + + if err := c.syncContainer(); err != nil { + return err + } + + if c.state.State == ContainerStateRunning && pause { + if err := c.runtime.ociRuntime.pauseContainer(c); err != nil { + return errors.Wrapf(err, "error pausing container %q", c.ID()) + } + defer func() { + if err := c.runtime.ociRuntime.unpauseContainer(c); err != nil { + logrus.Errorf("error unpausing container %q: %v", c.ID(), err) + } + }() + } + + tempFile, err := ioutil.TempFile(c.runtime.config.TmpDir, "podman-commit") + if err != nil { + return errors.Wrapf(err, "error creating temp file") + } + defer os.Remove(tempFile.Name()) + defer tempFile.Close() + + if err := c.export(tempFile.Name()); err != nil { + return err + } + return c.runtime.ImportImage(tempFile.Name(), options) } // Wait blocks on a container to exit and returns its exit code |