当前位置: 首页>>代码示例>>Golang>>正文


Golang DockerClient.RemoveImage方法代码示例

本文整理汇总了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
}
开发者ID:kadel,项目名称:dockercleaner,代码行数:32,代码来源:dockercleaner.go

示例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
}
开发者ID:dawidmalina,项目名称:docker-proper,代码行数:11,代码来源:docker-proper.go

示例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
}
开发者ID:th3architect,项目名称:sherdock,代码行数:54,代码来源:gc.go


注:本文中的github.com/samalba/dockerclient.DockerClient.RemoveImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。