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


Golang dockerclient.Client类代码示例

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


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

示例1: afterContainerReady

// afterContainerReady waits for the cluster ready and then sends the struct{}
// on the returned channel. Detection of cluster ready is very heuristic way,
// just checking number of container which is needed for running cluster.
func afterContainerReady(c dockerclient.Client) chan struct{} {
	doneCh := make(chan struct{})

	// Marshaling to post filter as API request
	filterLocalMasterStr, err := json.Marshal(FilterLocalMaster)
	if err != nil {
		// Should not reach here....
		panic(fmt.Sprintf(
			"Failed to marshal FilterLocalMaster: %s", err))
	}

	ticker := time.NewTicker(CheckInterval)
	go func() {
		fmt.Fprintf(os.Stderr, "Wait until containers are readly")
		for _ = range ticker.C {
			fmt.Fprintf(os.Stderr, ".")
			// Get Container info from deamon based on fileter
			localMasters, err := c.ListContainers(true, false, (string)(filterLocalMasterStr))
			if err != nil {
				// Just ignore error
				continue
			}

			if len(localMasters) > 3 {
				fmt.Fprintf(os.Stderr, "\n")
				doneCh <- struct{}{}
				ticker.Stop()
			}
		}
	}()

	return doneCh
}
开发者ID:syohex,项目名称:boot2kubernetes,代码行数:36,代码来源:up.go

示例2: BindingAddr

// BindingAddr provides the address for the container and binding.
func BindingAddr(d dockerclient.Client, name, binding string) (string, error) {
	ci, err := d.InspectContainer(name)
	if err != nil {
		return "", stackerr.Wrap(err)
	}

	ip, err := dockerIP(d)
	if err != nil {
		return "", err
	}

	hostname, err := etcHostsName(ip)
	if err != nil {
		return "", err
	}

	if hostname == "" {
		hostname = ip.String()
	}

	addr := fmt.Sprintf(
		"%s:%s",
		hostname,
		ci.NetworkSettings.Ports[binding][0].HostPort,
	)
	return addr, nil
}
开发者ID:hopkings2008,项目名称:dockerutil,代码行数:28,代码来源:binding.go

示例3: removeContainers

// removeContainers removes all containers parallelly.
// It retuns error channel and if something wrong, error is sent there.
func removeContainers(client dockerclient.Client, containers []dockerclient.Container, force, delVolume bool) (chan dockerclient.Container, chan error) {

	var wg sync.WaitGroup
	resultCh, errCh := make(chan dockerclient.Container), make(chan error)
	for _, container := range containers {
		wg.Add(1)
		go func(c dockerclient.Container) {
			defer wg.Done()
			if err := client.RemoveContainer(c.Id, force, delVolume); err != nil {
				errCh <- fmt.Errorf(
					"failed to remove %s (%s): %s", c.Names[0], c.Id, err)
				return
			}
			resultCh <- c
		}(container)
	}

	go func() {
		// Wait until all remove task and close error channnel then
		wg.Wait()
		close(resultCh)
		close(errCh)
	}()

	return resultCh, errCh
}
开发者ID:syohex,项目名称:boot2kubernetes,代码行数:28,代码来源:destroy.go

示例4: PullImage

func PullImage(client dockerclient.Client, service *Service, image string) error {
	taglessRemote, tag := parsers.ParseRepositoryTag(image)
	if tag == "" {
		image = utils.ImageReference(taglessRemote, tags.DEFAULTTAG)
	}

	repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
	if err != nil {
		return err
	}

	authConfig := cliconfig.AuthConfig{}
	if service.context.ConfigFile != nil && repoInfo != nil && repoInfo.Index != nil {
		authConfig = registry.ResolveAuthConfig(service.context.ConfigFile, repoInfo.Index)
	}

	err = client.PullImage(image, &dockerclient.AuthConfig{
		Username: authConfig.Username,
		Password: authConfig.Password,
		Email:    authConfig.Email,
	})

	if err != nil {
		logrus.Errorf("Failed to pull image %s: %v", image, err)
	}

	return err
}
开发者ID:Jdesk,项目名称:os,代码行数:28,代码来源:container.go

示例5: run

func run(client dockerclient.Client, args []string, input string) (int, error) {

	image := "drone/drone-exec:latest"
	entrypoint := []string{"/bin/drone-exec"}
	args = append(args, "--", input)

	conf := &dockerclient.ContainerConfig{
		Image:      image,
		Entrypoint: entrypoint,
		Cmd:        args,
		HostConfig: dockerclient.HostConfig{
			Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
		},
		Volumes: map[string]struct{}{
			"/var/run/docker.sock": struct{}{},
		},
	}

	info, err := docker.Run(client, conf, false)
	if err != nil {
		return 0, err
	}

	client.StopContainer(info.Id, 15)
	client.RemoveContainer(info.Id, true, true)
	return info.State.ExitCode, err
}
开发者ID:gregorygtseng,项目名称:drone-cli,代码行数:27,代码来源:exec.go

示例6: checkContainers

func checkContainers(mappings []Mapping, docker dockerclient.Client, etc *etcd.Client) {

	for {
		pointers := map[string]Server{}
		containers, err := docker.ListContainers(false, true, "")
		logFatalIf(err)

		for _, container := range containers {
			name := extractContainerName(container)

			for _, mapping := range mappings {

				if isMappedName(mapping, name) {
					ports := extractContainerPorts(mapping, container)

					for _, port := range ports {
						key := fmt.Sprintf("/nginx/servers/%s/%s/%s", CLUSTER, mapping.Upstream, container.Id[0:12])
						pointers[key] = newServer(HOST, port)
					}
				}
			}
		}

		for key, server := range pointers {
			go announce(key, server, etc)
		}

		time.Sleep(5 * time.Second)
	}

}
开发者ID:lrolaz,项目名称:nginx-confd,代码行数:31,代码来源:app.go

示例7: Stop

// Stop a container
func Stop(docker dockerclient.Client, id string) string {
	// Stop the container (with 5 seconds timeout)
	err := docker.StopContainer(id, 5)
	if err != nil {
		log.Fatal(err)
	}
	return "OK"
}
开发者ID:ds0nt,项目名称:klouds-agent,代码行数:9,代码来源:control.go

示例8: Start

// Start a container
func Start(docker dockerclient.Client, id string) string {
	// Start the container
	hostConfig := &dockerclient.HostConfig{}
	err := docker.StartContainer(id, hostConfig)
	if err != nil {
		log.Fatal(err)
	}
	return "OK"
}
开发者ID:ds0nt,项目名称:klouds-agent,代码行数:10,代码来源:control.go

示例9: List

// List the containers
func List(docker dockerclient.Client) []dockerclient.Container {
	// Get only running containers
	containers, err := docker.ListContainers(true, false, "")

	if err != nil {
		log.Fatal(err)
	}

	return containers
}
开发者ID:ds0nt,项目名称:klouds-agent,代码行数:11,代码来源:control.go

示例10: createContainer

// createContainer creates a new container using the specified options. Per the
// docker API, the created container is not running and must be started
// explicitly.
func createContainer(client dockerclient.Client, config dockerclient.ContainerConfig) (*Container, error) {
	id, err := client.CreateContainer(&config, "")
	if err != nil {
		return nil, err
	}
	return &Container{
		ID:            id,
		containerInfo: dockerclient.ContainerInfo{Id: id},
		client:        client}, nil
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:13,代码来源:docker.go

示例11: waitFor

func waitFor(once *sync.Once, client dockerclient.Client, endpoint string) {
	once.Do(func() {
		err := ClientOK(endpoint, func() bool {
			_, err := client.Info()
			return err == nil
		})
		if err != nil {
			panic(err.Error())
		}
	})
}
开发者ID:Jdesk,项目名称:os,代码行数:11,代码来源:client_factory.go

示例12: GetContainerByName

func GetContainerByName(client dockerclient.Client, name string) (*dockerclient.Container, error) {
	containers, err := client.ListContainers(true, false, NAME.Eq(name))
	if err != nil {
		return nil, err
	}

	if len(containers) == 0 {
		return nil, nil
	}

	return &containers[0], nil
}
开发者ID:rowhit,项目名称:os,代码行数:12,代码来源:functions.go

示例13: GetContainersByFilter

func GetContainersByFilter(client dockerclient.Client, filter ...string) ([]dockerclient.Container, error) {
	filterResult := ""

	for _, value := range filter {
		if filterResult == "" {
			filterResult = value
		} else {
			filterResult = And(filterResult, value)
		}
	}

	return client.ListContainers(true, false, filterResult)
}
开发者ID:rowhit,项目名称:os,代码行数:13,代码来源:functions.go

示例14: Create

// Create a container
func Create(docker dockerclient.Client, name string, image string) string {
	// Create a container
	containerConfig := &dockerclient.ContainerConfig{
		Image: image,
		// Cmd:   []string{"bash"},
		AttachStdin: true,
		Tty:         true}
	id, err := docker.CreateContainer(containerConfig, name)
	if err != nil {
		log.Fatal(err)
	}
	return id
}
开发者ID:ds0nt,项目名称:klouds-agent,代码行数:14,代码来源:control.go

示例15: Wait

// Wait blocks until the named container exits, returning the exit information.
func Wait(client dockerclient.Client, name string) (*dockerclient.ContainerInfo, error) {

	defer func() {
		client.StopContainer(name, 5)
		client.KillContainer(name, "9")
	}()

	for attempts := 0; attempts < 5; attempts++ {
		done := client.Wait(name)
		<-done

		info, err := client.InspectContainer(name)
		if err != nil {
			return nil, err
		}

		if !info.State.Running {
			return info, nil
		}

		log.Debugf("attempting to resume waiting after %d attempts.\n", attempts)
	}

	return nil, errors.New("reached maximum wait attempts")
}
开发者ID:clanstyles,项目名称:drone,代码行数:26,代码来源:docker.go


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