|
@@ -1,6 +1,9 @@
|
|
|
package daemon
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+ "runtime"
|
|
|
+
|
|
|
"github.com/docker/docker/image"
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
"github.com/docker/docker/pkg/ioutils"
|
|
@@ -15,17 +18,35 @@ type ContainerCommitConfig struct {
|
|
|
Tag string
|
|
|
Author string
|
|
|
Comment string
|
|
|
- Config *runconfig.Config
|
|
|
+ // merge container config into commit config before commit
|
|
|
+ MergeConfigs bool
|
|
|
+ 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) {
|
|
|
+func (daemon *Daemon) Commit(name string, c *ContainerCommitConfig) (*image.Image, error) {
|
|
|
+ container, err := daemon.Get(name)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // It is not possible to commit a running container on Windows
|
|
|
+ if runtime.GOOS == "windows" && container.IsRunning() {
|
|
|
+ return nil, fmt.Errorf("Windows does not support commit of a running container")
|
|
|
+ }
|
|
|
+
|
|
|
if c.Pause && !container.isPaused() {
|
|
|
daemon.containerPause(container)
|
|
|
defer daemon.containerUnpause(container)
|
|
|
}
|
|
|
|
|
|
+ if c.MergeConfigs {
|
|
|
+ if err := runconfig.Merge(c.Config, container.Config); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
rwTar, err := daemon.exportContainerRw(container)
|
|
|
if err != nil {
|
|
|
return nil, err
|