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