-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Expand file tree
/
Copy pathnetwork_connect.go
More file actions
40 lines (33 loc) · 1.12 KB
/
network_connect.go
File metadata and controls
40 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package client
import (
"context"
"github.com/moby/moby/api/types/network"
)
// NetworkConnectOptions represents the data to be used to connect a container to the
// network.
type NetworkConnectOptions struct {
Container string
EndpointConfig *network.EndpointSettings
}
// NetworkConnectResult represents the result of a NetworkConnect operation.
type NetworkConnectResult struct {
// Currently empty; placeholder for future fields.
}
// NetworkConnect connects a container to an existent network in the docker host.
func (cli *Client) NetworkConnect(ctx context.Context, networkID string, options NetworkConnectOptions) (NetworkConnectResult, error) {
networkID, err := trimID("network", networkID)
if err != nil {
return NetworkConnectResult{}, err
}
containerID, err := trimID("container", options.Container)
if err != nil {
return NetworkConnectResult{}, err
}
nc := network.ConnectRequest{
Container: containerID,
EndpointConfig: options.EndpointConfig,
}
resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, nc, nil)
defer ensureReaderClosed(resp)
return NetworkConnectResult{}, err
}