container_commit.go 951 B

123456789101112131415161718192021222324252627282930313233343536
  1. package client
  2. import (
  3. "encoding/json"
  4. "net/url"
  5. "github.com/docker/engine-api/types"
  6. "golang.org/x/net/context"
  7. )
  8. // ContainerCommit applies changes into a container and creates a new tagged image.
  9. func (cli *Client) ContainerCommit(ctx context.Context, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) {
  10. query := url.Values{}
  11. query.Set("container", options.ContainerID)
  12. query.Set("repo", options.RepositoryName)
  13. query.Set("tag", options.Tag)
  14. query.Set("comment", options.Comment)
  15. query.Set("author", options.Author)
  16. for _, change := range options.Changes {
  17. query.Add("changes", change)
  18. }
  19. if options.Pause != true {
  20. query.Set("pause", "0")
  21. }
  22. var response types.ContainerCommitResponse
  23. resp, err := cli.post(ctx, "/commit", query, options.Config, nil)
  24. if err != nil {
  25. return response, err
  26. }
  27. err = json.NewDecoder(resp.body).Decode(&response)
  28. ensureReaderClosed(resp)
  29. return response, err
  30. }