Skip to content

Commit

Permalink
refactor use of container struct from daemon
Browse files Browse the repository at this point in the history
 - use Exists instead of Get
 - push Get inside of daemonbuilder

Signed-off-by: Morgan Bauer <[email protected]>
  • Loading branch information
MHBauer committed Oct 12, 2015
1 parent 96965e2 commit 844fb29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions api/server/router/local/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/daemon/daemonbuilder"
derr "github.com/docker/docker/errors"
"github.com/docker/docker/graph"
"github.com/docker/docker/graph/tags"
"github.com/docker/docker/pkg/archive"
Expand Down Expand Up @@ -63,12 +64,11 @@ func (s *router) postCommit(ctx context.Context, w http.ResponseWriter, r *http.
Config: c,
}

container, err := s.daemon.Get(cname)
if err != nil {
return err
if !s.daemon.Exists(cname) {
return derr.ErrorCodeNoSuchContainer.WithArgs(cname)
}

imgID, err := dockerfile.Commit(container, s.daemon, commitCfg)
imgID, err := dockerfile.Commit(cname, s.daemon, commitCfg)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion builder/dockerfile/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ func BuildFromConfig(config *runconfig.Config, changes []string) (*runconfig.Con

// Commit will create a new image from a container's changes
// TODO: remove daemon, make Commit a method on *Builder ?
func Commit(container *daemon.Container, 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")
Expand Down

0 comments on commit 844fb29

Please sign in to comment.