2014-07-31 20:57:21 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-04-10 20:41:43 +00:00
|
|
|
type ContainerCommitConfig struct {
|
|
|
|
Pause bool
|
|
|
|
Repo string
|
|
|
|
Tag string
|
|
|
|
Author string
|
|
|
|
Comment string
|
|
|
|
Changes []string
|
2015-04-16 21:26:33 +00:00
|
|
|
Config *runconfig.Config
|
2014-07-31 20:57:21 +00: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 11:28:40 +00:00
|
|
|
if pause && !container.IsPaused() {
|
2014-07-31 20:57:21 +00: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
|
|
|
|
}
|
|
|
|
defer rwTar.Close()
|
|
|
|
|
|
|
|
// Create a new image from the container's base layers + a new layer from container changes
|
|
|
|
var (
|
2014-10-28 21:06:23 +00:00
|
|
|
containerID, parentImageID string
|
|
|
|
containerConfig *runconfig.Config
|
2014-07-31 20:57:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if container != nil {
|
|
|
|
containerID = container.ID
|
2014-10-28 21:06:23 +00:00
|
|
|
parentImageID = container.ImageID
|
2014-07-31 20:57:21 +00:00
|
|
|
containerConfig = container.Config
|
|
|
|
}
|
|
|
|
|
2014-10-28 21:06:23 +00:00
|
|
|
img, err := daemon.graph.Create(rwTar, containerID, parentImageID, comment, author, containerConfig, config)
|
2014-07-31 20:57:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the image if needed
|
|
|
|
if repository != "" {
|
2015-04-14 02:46:29 +00:00
|
|
|
if err := daemon.repositories.Tag(repository, tag, img.ID, true); err != nil {
|
2014-07-31 20:57:21 +00:00
|
|
|
return img, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return img, nil
|
|
|
|
}
|