Skip to content

Instantly share code, notes, and snippets.

@ranjib
Last active May 25, 2016 21:28
Show Gist options
  • Save ranjib/d9f9798393a25971282de9e4093e49f2 to your computer and use it in GitHub Desktop.
Save ranjib/d9f9798393a25971282de9e4093e49f2 to your computer and use it in GitHub Desktop.
docker image squashing
import(
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
)
func Squash() {
defaultHeaders := map[string]string{"User-Agent": "abc-1.0"}
cli, _ := client.NewClient("unix:///var/run/docker.sock", "v1.22", nil, defaultHeaders)
ctx := context.Background()
saveBody, _ := cli.ImageSave(ctx, []string{"image-id"})
src := types.ImageImportSource{
Source: saveBody,
SourceName: "-",
}
importOpts := types.ImageImportOptions{
Message: "Squashing by foo",
Tag: "squashed",
Changes: []string{"CMD /bin/bash"},
}
cli.ImageImport(ctx, src, "foo/abr", importOpts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment