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


Golang dockerclient.HostConfig類代碼示例

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


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

示例1: StartContainer

// StartContainer starts a container and links to an
// ambassador container sharing the build machiens volume.
func (c *Client) StartContainer(id string, conf *dockerclient.HostConfig) error {
	conf.VolumesFrom = append(conf.VolumesFrom, c.info.Id)
	if len(conf.NetworkMode) == 0 {
		conf.NetworkMode = "container:" + c.info.Id
	}
	return c.Client.StartContainer(id, conf)
}
開發者ID:objectpartners,項目名稱:drone-exec,代碼行數:9,代碼來源:docker.go

示例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)
}
開發者ID:xtraclabs,項目名稱:roll,代碼行數:16,代碼來源:docker_support.go

示例3: 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
}
開發者ID:nickschuch,項目名稱:up,代碼行數:41,代碼來源:container.go

示例4: addNetNs

func (c *Container) addNetNs(config *dockerclient.HostConfig, service project.Service, containers []project.Container) (*dockerclient.HostConfig, error) {
	if len(containers) == 0 {
		return nil, fmt.Errorf("Failed to find container for networks ns %", c.service.Config().Net)
	}

	id, err := containers[0].Id()
	if err != nil {
		return nil, err
	}

	config.NetworkMode = "container:" + id
	return config, nil
}
開發者ID:nickschuch,項目名稱:up,代碼行數:13,代碼來源:container.go

示例5: addIpc

func (c *Container) addIpc(config *dockerclient.HostConfig, service project.Service, containers []project.Container) (*dockerclient.HostConfig, error) {
	if len(containers) == 0 {
		return nil, fmt.Errorf("Failed to find container for IPC %v", c.service.Config().Ipc)
	}

	id, err := containers[0].ID()
	if err != nil {
		return nil, err
	}

	config.IpcMode = "container:" + id
	return config, nil
}
開發者ID:alena1108,項目名稱:rancher-compose-executor,代碼行數:13,代碼來源:container.go


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