mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
abd72d4008
- some method names were changed to have a 'Locking' suffix, as the downcased versions already existed, and the existing functions simply had locks around the already downcased version. - deleting unused functions - package comment - magic numbers replaced by golang constants - comments all over Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package daemon
|
|
|
|
import (
|
|
"github.com/docker/docker/image"
|
|
"github.com/docker/docker/runconfig"
|
|
)
|
|
|
|
// ContainerCommitConfig contains build configs for commit operation,
|
|
// and is used when making a commit with the current state of the container.
|
|
type ContainerCommitConfig struct {
|
|
Pause bool
|
|
Repo string
|
|
Tag string
|
|
Author string
|
|
Comment string
|
|
Config *runconfig.Config
|
|
}
|
|
|
|
// 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, c *ContainerCommitConfig) (*image.Image, error) {
|
|
if c.Pause && !container.isPaused() {
|
|
container.pause()
|
|
defer container.unpause()
|
|
}
|
|
|
|
rwTar, err := container.exportRw()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() {
|
|
if rwTar != nil {
|
|
rwTar.Close()
|
|
}
|
|
}()
|
|
|
|
// Create a new image from the container's base layers + a new layer from container changes
|
|
var (
|
|
containerID, parentImageID string
|
|
containerConfig *runconfig.Config
|
|
)
|
|
|
|
if container != nil {
|
|
containerID = container.ID
|
|
parentImageID = container.ImageID
|
|
containerConfig = container.Config
|
|
}
|
|
|
|
img, err := daemon.graph.Create(rwTar, containerID, parentImageID, c.Comment, c.Author, containerConfig, c.Config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Register the image if needed
|
|
if c.Repo != "" {
|
|
if err := daemon.repositories.Tag(c.Repo, c.Tag, img.ID, true); err != nil {
|
|
return img, err
|
|
}
|
|
}
|
|
container.logEvent("commit")
|
|
return img, nil
|
|
}
|