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


Golang Client.ListContainers方法代码示例

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


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

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

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

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

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

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

示例6: GetContainerById

func GetContainerById(client dockerclient.Client, id string) (*dockerclient.Container, error) {
	containers, err := client.ListContainers(true, false, "")
	if err != nil {
		return nil, err
	}

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

	for _, c := range containers {
		if c.Id == id {
			return &c, nil
		}
	}

	return nil, nil
}
开发者ID:rowhit,项目名称:os,代码行数:18,代码来源:functions.go


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