當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。