github.com/kunnos/engine@v1.13.1/client/container_commit.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "errors" 6 "net/url" 7 8 distreference "github.com/docker/distribution/reference" 9 "github.com/docker/docker/api/types" 10 "github.com/docker/docker/api/types/reference" 11 "golang.org/x/net/context" 12 ) 13 14 // ContainerCommit applies changes into a container and creates a new tagged image. 15 func (cli *Client) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) { 16 var repository, tag string 17 if options.Reference != "" { 18 distributionRef, err := distreference.ParseNamed(options.Reference) 19 if err != nil { 20 return types.IDResponse{}, err 21 } 22 23 if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical { 24 return types.IDResponse{}, errors.New("refusing to create a tag with a digest reference") 25 } 26 27 tag = reference.GetTagFromNamedRef(distributionRef) 28 repository = distributionRef.Name() 29 } 30 31 query := url.Values{} 32 query.Set("container", container) 33 query.Set("repo", repository) 34 query.Set("tag", tag) 35 query.Set("comment", options.Comment) 36 query.Set("author", options.Author) 37 for _, change := range options.Changes { 38 query.Add("changes", change) 39 } 40 if options.Pause != true { 41 query.Set("pause", "0") 42 } 43 44 var response types.IDResponse 45 resp, err := cli.post(ctx, "/commit", query, options.Config, nil) 46 if err != nil { 47 return response, err 48 } 49 50 err = json.NewDecoder(resp.body).Decode(&response) 51 ensureReaderClosed(resp) 52 return response, err 53 }