本文整理匯總了Golang中github.com/docker/engine-api/client.Client.NetworkConnect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.NetworkConnect方法的具體用法?Golang Client.NetworkConnect怎麽用?Golang Client.NetworkConnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/engine-api/client.Client
的用法示例。
在下文中一共展示了Client.NetworkConnect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runTorContainer
func runTorContainer(cli *client.Client, ident, imageID, network string) (string, error) {
config := &types.ContainerCreateConfig{
Name: ident,
Config: &containerTypes.Config{
Image: imageID,
},
}
resp, err := cli.ContainerCreate(config.Config, config.HostConfig, config.NetworkingConfig, config.Name)
if err != nil {
return "", err
}
// TODO: Remove container on failure.
for _, warning := range resp.Warnings {
log.Warn(warning)
}
if err := cli.ContainerStart(resp.ID); err != nil {
return "", err
}
// Connect to the network.
if err := cli.NetworkConnect(network, resp.ID, nil); err != nil {
return "", err
}
return resp.ID, err
}
示例2: ConnectOnionNetwork
// ConnectOnionNetwork connects a target container to the onion network, allowing
// the container to be accessed by the Tor relay container.
func ConnectOnionNetwork(cli *client.Client, target, network string) error {
// XXX: Should configure this to use a subnet like 10.x.x.x.
options := &networkTypes.EndpointSettings{}
return cli.NetworkConnect(network, target, options)
}