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


Golang dockerclient.DockerClient类代码示例

本文整理汇总了Golang中github.com/samalba/dockerclient.DockerClient的典型用法代码示例。如果您正苦于以下问题:Golang DockerClient类的具体用法?Golang DockerClient怎么用?Golang DockerClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DockerClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: GetContainers

func (n *Node) GetContainers(do *dockerclient.DockerClient) ([]dockerclient.Container, error) {
	containers, err := do.ListContainers(false, false, "")
	if err != nil {
		log.Fatal(err)
	}
	return containers, err
}
开发者ID:breeze7086,项目名称:domonitor,代码行数:7,代码来源:NodeInfo.go

示例3: GetImages

func (n *Node) GetImages(do *dockerclient.DockerClient) ([]*dockerclient.Image, error) {
	images, err := do.ListImages(false)
	if err != nil {
		log.Fatal(err)
	}
	return images, err
}
开发者ID:breeze7086,项目名称:domonitor,代码行数:7,代码来源:NodeInfo.go

示例4: ListImagesDetailed

func ListImagesDetailed(dockerClient *dockerclient.DockerClient, all bool) ([]*DetailedImageInfo, error) {
	images, err := dockerClient.ListImages(all)
	if err != nil {
		return nil, err
	}
	var result = make([]*DetailedImageInfo, len(images))
	for i, image := range images {
		imagesDetails, _ := InspectImage(dockerClient, image.Id)
		detailedImageInfo := DetailedImageInfo{
			Created:       image.Created,
			Id:            image.Id,
			ParentId:      image.ParentId,
			RepoTags:      image.RepoTags,
			Size:          image.Size,
			VirtualSize:   image.VirtualSize,
			Architecture:  imagesDetails.Architecture,
			Author:        imagesDetails.Author,
			Comment:       imagesDetails.Comment,
			Container:     imagesDetails.Container,
			DockerVersion: imagesDetails.Container,
			Os:            imagesDetails.Os}
		result[i] = &detailedImageInfo
	}
	return result, nil
}
开发者ID:th3architect,项目名称:sherdock,代码行数:25,代码来源:images.go

示例5: stopCotainers

func stopCotainers(docker *dockerclient.DockerClient, imageIDs []string) []error {
	var errors []error
	if !noConfirm {
		var answer string
		fmt.Printf("This will stop %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 {
		stopErr := docker.StopContainer(imageID, 10)
		if stopErr != nil {
			errors = append(errors, stopErr)
		} else {
			log.Printf("STOPPED: %v", imageID)
		}
	}
	if len(errors) > 0 {
		return errors
	}
	return nil
}
开发者ID:kadel,项目名称:dockercleaner,代码行数:26,代码来源:dockercleaner.go

示例6: InspectContainer

func (n *Node) InspectContainer(do *dockerclient.DockerClient, id string) (*dockerclient.ContainerInfo, error) {
	containerInfo := &dockerclient.ContainerInfo{}
	var err error
	containerInfo, err = do.InspectContainer(id)
	if err != nil {
		log.Fatal(err)
	}
	return containerInfo, err
}
开发者ID:breeze7086,项目名称:domonitor,代码行数:9,代码来源:NodeInfo.go

示例7: stopAndDeleteDevice

func stopAndDeleteDevice(deviceSn string, docker *dc.DockerClient) error {
	container := "device" + deviceSn
	err := docker.KillContainer(container)
	if err != nil {
		return err
	}

	err = docker.RemoveContainer(container)
	return nil
}
开发者ID:jvermillard,项目名称:daas,代码行数:10,代码来源:main.go

示例8: 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

示例9: GetInjectorsForPolicy

func GetInjectorsForPolicy(client *docker.DockerClient, name string) ([]injector, error) {
	is := []injector{}
	cs, err := client.ListContainers(true, false, fmt.Sprintf(`{"label":["%s=%s"]}`, AGENT_LABEL, name))
	if err != nil {
		return is, err
	}
	for _, c := range cs {
		is = append(is, InjectorFromContainer(c))
	}
	return is, nil
}
开发者ID:ZhukovAlexander,项目名称:entropy,代码行数:11,代码来源:policy.go

示例10: removeContainers

func removeContainers(client *dockerclient.DockerClient, containers []*dockerclient.ContainerInfo) error {
	for _, container := range containers {
		log.Printf("rm %s (%s)", container.Id, container.Name)
		if !*dry {
			if err := client.RemoveContainer(container.Id, false, false); err != nil {
				debug("Couldn't remove container: %s", err)
			}
		}
	}
	return nil
}
开发者ID:dawidmalina,项目名称:docker-proper,代码行数:11,代码来源:docker-proper.go

示例11: ListContainersDetailed

func ListContainersDetailed(dockerClient *dockerclient.DockerClient) ([]*dockerclient.ContainerInfo, error) {
	containers, err := dockerClient.ListContainers(true, false, "")
	if err != nil {
		return nil, err
	}
	var result = make([]*dockerclient.ContainerInfo, len(containers))
	for i, container := range containers {
		containerInfo, err := dockerClient.InspectContainer(container.Id)
		if err != nil {
			return nil, err
		}
		result[i] = containerInfo
	}
	return result, nil
}
开发者ID:th3architect,项目名称:sherdock,代码行数:15,代码来源:containers.go

示例12: list_containers

func list_containers(docker *dockerclient.DockerClient) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		// Get only running containers
		containers, err := docker.ListContainers(false, false, "")
		if err != nil {
			log.Fatal(err)
		}

		dat, err := json.MarshalIndent(&containers, "", "  ")
		if err != nil {
			log.Fatal(err)
		}
		fmt.Fprintf(w, string(dat))
	}
}
开发者ID:odewahn,项目名称:thebe-server,代码行数:16,代码来源:list.go

示例13: startContainer

func startContainer(docker *dockerclient.DockerClient, containerId string, additionalCapabilities []string, ctx *ContainerContext) error {
	//Build the port bindings needed when running the container
	dockerHostConfig := new(dockerclient.HostConfig)
	dockerHostConfig.PortBindings = make(map[string][]dockerclient.PortBinding)
	for k, v := range ctx.PortContext {
		pb := dockerclient.PortBinding{HostPort: v}
		portBindings := []dockerclient.PortBinding{pb}
		dockerHostConfig.PortBindings[k] = portBindings
	}

	dockerHostConfig.Links = ctx.Links
	dockerHostConfig.CapAdd = additionalCapabilities

	//Start the container
	return docker.StartContainer(containerId, dockerHostConfig)
}
开发者ID:xtraclabs,项目名称:roll,代码行数:16,代码来源:docker_support.go

示例14: requiredImageAvailable

func requiredImageAvailable(docker *dockerclient.DockerClient, name string) bool {
	images, err := docker.ListImages(true)
	if err != nil {
		log.Fatal(err)
	}

	for _, i := range images {
		for _, t := range i.RepoTags {
			if strings.Index(t, name) == 0 {
				return true
			}
		}
	}

	return false
}
开发者ID:xtraclabs,项目名称:roll,代码行数:16,代码来源:docker_support.go

示例15: InspectImage

func InspectImage(dockerClient *dockerclient.DockerClient, id string) (*dockerclient.ImageInfo, error) {
	cachedImageInfo, _ := imageCache.Get(id)
	if cachedImageInfo == nil {
		imageInfo, err := dockerClient.InspectImage(id)
		if err != nil {
			return nil, err
		}
		imageCache.Add(id, imageInfo)
		return imageInfo, nil
	} else {
		if cachedImageInfoCasted, ok := cachedImageInfo.(*dockerclient.ImageInfo); ok {
			return cachedImageInfoCasted, nil
		} else {
			return nil, fmt.Errorf("Cache casting error")
		}
	}
}
开发者ID:th3architect,项目名称:sherdock,代码行数:17,代码来源:images.go


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