network_connect.go 556 B

12345678910111213141516171819
  1. package client
  2. import (
  3. "github.com/docker/engine-api/types"
  4. "github.com/docker/engine-api/types/network"
  5. "golang.org/x/net/context"
  6. )
  7. // NetworkConnect connects a container to an existent network in the docker host.
  8. func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error {
  9. nc := types.NetworkConnect{
  10. Container: containerID,
  11. EndpointConfig: config,
  12. }
  13. resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, nc, nil)
  14. ensureReaderClosed(resp)
  15. return err
  16. }