2014-08-01 00:57:21 +04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-07-20 20:57:15 +03:00
|
|
|
"github.com/docker/docker/image"
|
2014-08-01 00:57:21 +04:00
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-07-31 00:01:53 +03:00
|
|
|
// ContainerCommitConfig contains build configs for commit operation,
|
|
|
|
// and is used when making a commit with the current state of the container.
|
2015-04-10 23:41:43 +03:00
|
|
|
type ContainerCommitConfig struct {
|
|
|
|
Pause bool
|
|
|
|
Repo string
|
|
|
|
Tag string
|
|
|
|
Author string
|
|
|
|
Comment string
|
2015-04-17 00:26:33 +03:00
|
|
|
Config *runconfig.Config
|
2014-08-01 00:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Commit creates a new filesystem image from the current state of a container.
|
2015-07-31 00:01:53 +03:00
|
|
|
// The image can optionally be tagged into a repository.
|
2015-09-29 20:51:40 +03:00
|
|
|
func (daemon *Daemon) Commit(container *Container, c *ContainerCommitConfig) (*image.Image, error) {
|
2015-07-31 00:01:53 +03:00
|
|
|
if c.Pause && !container.isPaused() {
|
2015-09-29 20:51:40 +03:00
|
|
|
container.pause()
|
|
|
|
defer container.unpause()
|
2014-08-01 00:57:21 +04:00
|
|
|
}
|
|
|
|
|
2015-09-03 00:31:15 +03:00
|
|
|
rwTar, err := container.exportContainerRw()
|
2014-08-01 00:57:21 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-04-25 01:03:53 +03:00
|
|
|
defer func() {
|
|
|
|
if rwTar != nil {
|
|
|
|
rwTar.Close()
|
|
|
|
}
|
|
|
|
}()
|
2014-08-01 00:57:21 +04:00
|
|
|
|
|
|
|
// Create a new image from the container's base layers + a new layer from container changes
|
2015-09-01 11:33:14 +03:00
|
|
|
img, err := daemon.graph.Create(rwTar, container.ID, container.ImageID, c.Comment, c.Author, container.Config, c.Config)
|
2014-08-01 00:57:21 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the image if needed
|
2015-06-20 13:40:37 +03:00
|
|
|
if c.Repo != "" {
|
|
|
|
if err := daemon.repositories.Tag(c.Repo, c.Tag, img.ID, true); err != nil {
|
2014-08-01 00:57:21 +04:00
|
|
|
return img, err
|
|
|
|
}
|
|
|
|
}
|
2015-09-29 20:51:40 +03:00
|
|
|
container.logEvent("commit")
|
2014-08-01 00:57:21 +04:00
|
|
|
return img, nil
|
|
|
|
}
|