diff --git a/dockerclient.go b/dockerclient.go index e96d274..f79bc53 100644 --- a/dockerclient.go +++ b/dockerclient.go @@ -692,3 +692,30 @@ func (client *DockerClient) BuildImage(image *BuildImage) (io.ReadCloser, error) uri := fmt.Sprintf("/%s/build?%s", APIVersion, v.Encode()) return client.doStreamRequest("POST", uri, image.Context, headers) } + +func (client *DockerClient) Commit(id string, c *ContainerConfig, repo, tag, comment, author string) (string, error) { + config, err := json.Marshal(c) + if err != nil { + return "", err + } + + v := url.Values{} + v.Set("container", id) + v.Set("repo", repo) + v.Set("tag", tag) + v.Set("comment", comment) + v.Set("author", author) + + uri := fmt.Sprintf("/%s/commit?%s", APIVersion, v.Encode()) + data, err := client.doRequest("POST", uri, config, nil) + if err != nil { + return "", err + } + + var img Image + if err := json.Unmarshal(data, &img); err != nil { + return "", err + } + + return img.Id, nil +} diff --git a/interface.go b/interface.go index 17f0641..73f4891 100644 --- a/interface.go +++ b/interface.go @@ -42,4 +42,5 @@ type Client interface { RenameContainer(oldName string, newName string) error ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error) BuildImage(image *BuildImage) (io.ReadCloser, error) + Commit(id string, c *ContainerConfig, repo, tag, comment, author string) (string, error) } diff --git a/mockclient/mock.go b/mockclient/mock.go index 6babeea..186a0fa 100644 --- a/mockclient/mock.go +++ b/mockclient/mock.go @@ -155,3 +155,8 @@ func (client *MockClient) BuildImage(image *dockerclient.BuildImage) (io.ReadClo args := client.Mock.Called(image) return args.Get(0).(io.ReadCloser), args.Error(1) } + +func (client *MockClient) Commit(id string, c *ContainerConfig, repo, tag, comment, author string) (string, error) { + args := client.Mock.Called(id, c, repo, tag, comment, author) + return args.Strings(0), args.Error(1) +}