github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/bindings/containers/commit.go (about) 1 package containers 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/hanks177/podman/v4/pkg/bindings" 8 "github.com/hanks177/podman/v4/pkg/domain/entities" 9 ) 10 11 // Commit creates a container image from a container. The container is defined by nameOrID. Use 12 // the CommitOptions for finer grain control on characteristics of the resulting image. 13 func Commit(ctx context.Context, nameOrID string, options *CommitOptions) (entities.IDResponse, error) { 14 if options == nil { 15 options = new(CommitOptions) 16 } 17 id := entities.IDResponse{} 18 conn, err := bindings.GetClient(ctx) 19 if err != nil { 20 return id, err 21 } 22 params, err := options.ToParams() 23 if err != nil { 24 return entities.IDResponse{}, err 25 } 26 params.Set("container", nameOrID) 27 response, err := conn.DoRequest(ctx, nil, http.MethodPost, "/commit", params, nil) 28 if err != nil { 29 return id, err 30 } 31 defer response.Body.Close() 32 33 return id, response.Process(&id) 34 }