本文整理汇总了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)
}
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}