github.com/tompao/docker@v1.9.1/daemon/commit.go (about) 1 package daemon 2 3 import ( 4 "github.com/docker/docker/image" 5 "github.com/docker/docker/runconfig" 6 ) 7 8 // ContainerCommitConfig contains build configs for commit operation, 9 // and is used when making a commit with the current state of the container. 10 type ContainerCommitConfig struct { 11 Pause bool 12 Repo string 13 Tag string 14 Author string 15 Comment string 16 Config *runconfig.Config 17 } 18 19 // Commit creates a new filesystem image from the current state of a container. 20 // The image can optionally be tagged into a repository. 21 func (daemon *Daemon) Commit(container *Container, c *ContainerCommitConfig) (*image.Image, error) { 22 if c.Pause && !container.isPaused() { 23 container.pause() 24 defer container.unpause() 25 } 26 27 rwTar, err := container.exportContainerRw() 28 if err != nil { 29 return nil, err 30 } 31 defer func() { 32 if rwTar != nil { 33 rwTar.Close() 34 } 35 }() 36 37 // Create a new image from the container's base layers + a new layer from container changes 38 img, err := daemon.graph.Create(rwTar, container.ID, container.ImageID, c.Comment, c.Author, container.Config, c.Config) 39 if err != nil { 40 return nil, err 41 } 42 43 // Register the image if needed 44 if c.Repo != "" { 45 if err := daemon.repositories.Tag(c.Repo, c.Tag, img.ID, true); err != nil { 46 return img, err 47 } 48 } 49 container.logEvent("commit") 50 return img, nil 51 }