本文整理汇总了Golang中github.com/samalba/dockerclient.DockerClient.RemoveImage方法的典型用法代码示例。如果您正苦于以下问题:Golang DockerClient.RemoveImage方法的具体用法?Golang DockerClient.RemoveImage怎么用?Golang DockerClient.RemoveImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/samalba/dockerclient.DockerClient
的用法示例。
在下文中一共展示了DockerClient.RemoveImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteImage
func deleteImage(docker *dockerclient.DockerClient, imageIDs []string) []error {
var errors []error
if !noConfirm {
var answer string
fmt.Printf("This will delete %v images\n", len(imageIDs))
fmt.Printf("Do you want to continue? (yes/no)\n")
fmt.Scanln(&answer)
if answer != "yes" {
fmt.Printf("%v", answer)
return nil
}
}
for _, imageID := range imageIDs {
imageDelete, deleteErr := docker.RemoveImage(imageID)
if deleteErr != nil {
errors = append(errors, deleteErr)
}
for _, id := range imageDelete {
if id.Deleted != "" {
log.Printf("DELETED: %v", id.Deleted)
}
if id.Untagged != "" {
log.Printf("UNTAGGED: %#v", id.Untagged)
}
}
}
if len(errors) > 0 {
return errors
}
return nil
}
示例2: removeImages
func removeImages(client *dockerclient.DockerClient, images []*dockerclient.Image) error {
for _, image := range images {
log.Print("rmi ", image.Id)
if !*dry {
if _, err := client.RemoveImage(image.Id); err != nil {
debug("Couldn't remove image: %s", err)
}
}
}
return nil
}
示例3: runGC
func runGC(dockerClient *dockerclient.DockerClient, filters ...string) (bool, error) {
done := true
images, err := dockerClient.ListImages(true)
if err != nil {
return true, err
}
imagesToSave := make(map[string]bool)
for _, image := range images {
for _, repoTag := range image.RepoTags {
for _, regexFilter := range filters {
if match, _ := regexp.MatchString(regexFilter, repoTag); match {
log.Printf("Image %v matches regexp /%s/ to keep\n", image.Id, regexFilter)
imagesToSave[image.Id] = true
}
}
}
}
for _, i := range images {
if i.ParentId != "" {
log.Printf("Image %s has children\n", i.ParentId)
imagesToSave[i.ParentId] = true
}
}
containers, err := dockerClient.ListContainers(true, false, "")
if err != nil {
return true, err
}
for _, c := range containers {
info, _ := dockerClient.InspectContainer(c.Id)
log.Printf("Image %s in use by container %v\n", info.Image, c.Id)
imagesToSave[info.Image] = true
}
for _, image := range images {
if !imagesToSave[image.Id] {
log.Printf("Deleting image with image id %s %v\n", image.Id, image.RepoTags)
done = false
_, err = dockerClient.RemoveImage(image.Id)
if err != nil {
log.Println("Failed to delete image: ", err)
}
}
}
log.Println("Done with images GC")
return done, nil
}