當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DockerClient.StopContainer方法代碼示例

本文整理匯總了Golang中github.com/samalba/dockerclient.DockerClient.StopContainer方法的典型用法代碼示例。如果您正苦於以下問題:Golang DockerClient.StopContainer方法的具體用法?Golang DockerClient.StopContainer怎麽用?Golang DockerClient.StopContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/samalba/dockerclient.DockerClient的用法示例。


在下文中一共展示了DockerClient.StopContainer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

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

示例2: Exec

func (job *Job) Exec(docker *dockerclient.DockerClient,
	w io.Writer) error {

	containerConfig := &dockerclient.ContainerConfig{
		Image:        job.Image,
		Cmd:          []string{"/bin/bash", "-c", job.Cmd},
		AttachStdout: true,
		AttachStderr: true,
	}
	cid, err := docker.CreateContainer(containerConfig,
		fmt.Sprintf("spot-trader-job-%d", job.ID))
	if err != nil {
		return fmt.Errorf("creating container: %v", err)
	}
	defer func() {
		if err = docker.RemoveContainer(cid, false, false); err != nil {
			log.Printf("error removing container: %v", err)
		}
	}()
	options := &dockerclient.AttachOptions{Stdout: true, Stderr: true, Stream: true}
	stdout, err := docker.AttachContainer(cid, options)
	if err != nil {
		return fmt.Errorf("attaching: %v", err)
	}
	err = docker.StartContainer(cid, nil)
	if err != nil {
		return fmt.Errorf("starting container: %v", err)
	}
	done := make(chan struct{})
	go func() {
		err := copyDockerOut(w, w, stdout)
		if err != nil {
			log.Println(err)
		}
		stdout.Close()
		close(done)
	}()
	<-done
	err = docker.StopContainer(cid, 5)
	if err != nil {
		log.Printf("error stopping container: %v",
			err)
	}
	return nil
}
開發者ID:bajh,項目名稱:spot-trader,代碼行數:45,代碼來源:worker.go

示例3: stopVaultOnShutdown

func stopVaultOnShutdown(containerId string, docker *dockerclient.DockerClient) {
	log.Info("... stopping container ", containerId, "...")
	docker.StopContainer(containerId, 5)
	docker.RemoveContainer(containerId, true, false)
}
開發者ID:xtraclabs,項目名稱:roll,代碼行數:5,代碼來源:runvaultmachine.go


注:本文中的github.com/samalba/dockerclient.DockerClient.StopContainer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。