mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use name instead of container in Commit
It will make daemon interface separation easier later. Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
b52bedbd48
commit
38e34cf6da
5 changed files with 35 additions and 34 deletions
|
@ -114,7 +114,7 @@ type Docker interface {
|
||||||
// Remove removes a container specified by `id`.
|
// Remove removes a container specified by `id`.
|
||||||
Remove(id string, cfg *daemon.ContainerRmConfig) error
|
Remove(id string, cfg *daemon.ContainerRmConfig) error
|
||||||
// Commit creates a new Docker image from an existing Docker container.
|
// Commit creates a new Docker image from an existing Docker container.
|
||||||
Commit(*daemon.Container, *daemon.ContainerCommitConfig) (*image.Image, error)
|
Commit(string, *daemon.ContainerCommitConfig) (*image.Image, error)
|
||||||
// Copy copies/extracts a source FileInfo to a destination path inside a container
|
// Copy copies/extracts a source FileInfo to a destination path inside a container
|
||||||
// specified by a container object.
|
// specified by a container object.
|
||||||
// TODO: make an Extract method instead of passing `decompress`
|
// TODO: make an Extract method instead of passing `decompress`
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -258,16 +257,6 @@ func BuildFromConfig(config *runconfig.Config, changes []string) (*runconfig.Con
|
||||||
// Commit will create a new image from a container's changes
|
// Commit will create a new image from a container's changes
|
||||||
// TODO: remove daemon, make Commit a method on *Builder ?
|
// TODO: remove daemon, make Commit a method on *Builder ?
|
||||||
func Commit(containerName string, d *daemon.Daemon, c *CommitConfig) (string, error) {
|
func Commit(containerName string, d *daemon.Daemon, c *CommitConfig) (string, error) {
|
||||||
container, err := d.Get(containerName)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is not possible to commit a running container on Windows
|
|
||||||
if runtime.GOOS == "windows" && container.IsRunning() {
|
|
||||||
return "", fmt.Errorf("Windows does not support commit of a running container")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Config == nil {
|
if c.Config == nil {
|
||||||
c.Config = &runconfig.Config{}
|
c.Config = &runconfig.Config{}
|
||||||
}
|
}
|
||||||
|
@ -277,10 +266,6 @@ func Commit(containerName string, d *daemon.Daemon, c *CommitConfig) (string, er
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runconfig.Merge(newConfig, container.Config); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
commitCfg := &daemon.ContainerCommitConfig{
|
commitCfg := &daemon.ContainerCommitConfig{
|
||||||
Pause: c.Pause,
|
Pause: c.Pause,
|
||||||
Repo: c.Repo,
|
Repo: c.Repo,
|
||||||
|
@ -288,9 +273,10 @@ func Commit(containerName string, d *daemon.Daemon, c *CommitConfig) (string, er
|
||||||
Author: c.Author,
|
Author: c.Author,
|
||||||
Comment: c.Comment,
|
Comment: c.Comment,
|
||||||
Config: newConfig,
|
Config: newConfig,
|
||||||
|
MergeConfigs: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
img, err := d.Commit(container, commitCfg)
|
img, err := d.Commit(containerName, commitCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin
|
||||||
} else if hit {
|
} else if hit {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := b.create()
|
container, err := b.create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -73,11 +72,6 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin
|
||||||
defer b.docker.Unmount(container)
|
defer b.docker.Unmount(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := b.docker.Container(id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: Actually copy the struct
|
// Note: Actually copy the struct
|
||||||
autoConfig := *b.runConfig
|
autoConfig := *b.runConfig
|
||||||
autoConfig.Cmd = autoCmd
|
autoConfig.Cmd = autoCmd
|
||||||
|
@ -89,7 +83,7 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit the container
|
// Commit the container
|
||||||
image, err := b.docker.Commit(container, commitCfg)
|
image, err := b.docker.Commit(id, commitCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
|
@ -15,17 +18,35 @@ type ContainerCommitConfig struct {
|
||||||
Tag string
|
Tag string
|
||||||
Author string
|
Author string
|
||||||
Comment string
|
Comment string
|
||||||
|
// merge container config into commit config before commit
|
||||||
|
MergeConfigs bool
|
||||||
Config *runconfig.Config
|
Config *runconfig.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit creates a new filesystem image from the current state of a container.
|
// Commit creates a new filesystem image from the current state of a container.
|
||||||
// The image can optionally be tagged into a repository.
|
// 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() {
|
if c.Pause && !container.isPaused() {
|
||||||
daemon.containerPause(container)
|
daemon.containerPause(container)
|
||||||
defer daemon.containerUnpause(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)
|
rwTar, err := daemon.exportContainerRw(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -106,8 +106,8 @@ func (d Docker) Remove(id string, cfg *daemon.ContainerRmConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit creates a new Docker image from an existing Docker container.
|
// Commit creates a new Docker image from an existing Docker container.
|
||||||
func (d Docker) Commit(c *daemon.Container, cfg *daemon.ContainerCommitConfig) (*image.Image, error) {
|
func (d Docker) Commit(name string, cfg *daemon.ContainerCommitConfig) (*image.Image, error) {
|
||||||
return d.Daemon.Commit(c, cfg)
|
return d.Daemon.Commit(name, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call.
|
// Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call.
|
||||||
|
|
Loading…
Reference in a new issue