2014-07-31 16:57:21 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-04-10 16:41:43 -04:00
|
|
|
type ContainerCommitConfig struct {
|
|
|
|
Pause bool
|
|
|
|
Repo string
|
|
|
|
Tag string
|
|
|
|
Author string
|
|
|
|
Comment string
|
|
|
|
Changes []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.
|
|
|
|
// The image can optionally be tagged into a repository
|
|
|
|
func (daemon *Daemon) Commit(container *Container, repository, tag, comment, author string, pause bool, config *runconfig.Config) (*image.Image, error) {
|
2015-02-24 06:28:40 -05:00
|
|
|
if pause && !container.IsPaused() {
|
2014-07-31 16:57:21 -04:00
|
|
|
container.Pause()
|
|
|
|
defer container.Unpause()
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := container.Mount(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer container.Unmount()
|
|
|
|
|
|
|
|
rwTar, err := container.ExportRw()
|
|
|
|
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
|
|
|
|
var (
|
2014-10-28 17:06:23 -04:00
|
|
|
containerID, parentImageID string
|
|
|
|
containerConfig *runconfig.Config
|
2014-07-31 16:57:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if container != nil {
|
|
|
|
containerID = container.ID
|
2014-10-28 17:06:23 -04:00
|
|
|
parentImageID = container.ImageID
|
2014-07-31 16:57:21 -04:00
|
|
|
containerConfig = container.Config
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:06:23 -04:00
|
|
|
img, err := daemon.graph.Create(rwTar, containerID, parentImageID, comment, author, containerConfig, config)
|
2014-07-31 16:57:21 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the image if needed
|
|
|
|
if repository != "" {
|
2015-04-13 22:46:29 -04:00
|
|
|
if err := daemon.repositories.Tag(repository, tag, img.ID, true); err != nil {
|
2014-07-31 16:57:21 -04:00
|
|
|
return img, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return img, nil
|
|
|
|
}
|