Files
docker-cli/components/engine/daemon/commit.go
Jörg Thalheim 097c5661ee remove redundant mount/unmount calls on commit
daemon.Diff already implements mounting for naivegraphdriver and
aufs which does diffing on its owns does not need the container to be mounted.
So new filesystem driver should mount filesystems on their own if it is needed
to implement Diff(). This issue was reported by @kvasdopil while working on a
freebsd port, because freebsd does not allow mount an already mounted
filesystem. Also it saves some cycles for other operating systems as well.

Signed-off-by: Jörg Thalheim <joerg@higgsboson.tk>
Upstream-commit: 6473b0f127c63e8a45b2b456d69e3de03273705c
Component: engine
2015-05-28 08:43:31 +02:00

61 lines
1.4 KiB
Go

package daemon
import (
"github.com/docker/docker/image"
"github.com/docker/docker/runconfig"
)
type ContainerCommitConfig struct {
Pause bool
Repo string
Tag string
Author string
Comment string
Changes []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, repository, tag, comment, author string, pause bool, config *runconfig.Config) (*image.Image, error) {
if 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, comment, author, containerConfig, config)
if err != nil {
return nil, err
}
// Register the image if needed
if repository != "" {
if err := daemon.repositories.Tag(repository, tag, img.ID, true); err != nil {
return img, err
}
}
return img, nil
}