本文整理汇总了Golang中github.com/samalba/dockerclient.HostConfig.Links方法的典型用法代码示例。如果您正苦于以下问题:Golang HostConfig.Links方法的具体用法?Golang HostConfig.Links怎么用?Golang HostConfig.Links使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/samalba/dockerclient.HostConfig
的用法示例。
在下文中一共展示了HostConfig.Links方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: populateAdditionalHostConfig
func (c *Container) populateAdditionalHostConfig(hostConfig *dockerclient.HostConfig) error {
links := map[string]string{}
for _, link := range c.service.DependentServices() {
if _, ok := c.service.context.Project.Configs[link.Target]; !ok {
continue
}
service, err := c.service.context.Project.CreateService(link.Target)
if err != nil {
return err
}
containers, err := service.Containers()
if err != nil {
return err
}
if link.Type == project.REL_TYPE_LINK {
c.addLinks(links, service, link, containers)
} else if link.Type == project.REL_TYPE_IPC_NAMESPACE {
hostConfig, err = c.addIpc(hostConfig, service, containers)
} else if link.Type == project.REL_TYPE_NET_NAMESPACE {
hostConfig, err = c.addNetNs(hostConfig, service, containers)
}
if err != nil {
return err
}
}
hostConfig.Links = []string{}
for k, v := range links {
hostConfig.Links = append(hostConfig.Links, strings.Join([]string{v, k}, ":"))
}
for _, v := range c.service.Config().ExternalLinks {
hostConfig.Links = append(hostConfig.Links, v)
}
return nil
}
示例2: 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)
}