(dockerCLI command.Cli)
| 29 | } |
| 30 | |
| 31 | func newConnectCommand(dockerCLI command.Cli) *cobra.Command { |
| 32 | options := connectOptions{ |
| 33 | links: opts.NewListOpts(opts.ValidateLink), |
| 34 | } |
| 35 | |
| 36 | cmd := &cobra.Command{ |
| 37 | Use: "connect [OPTIONS] NETWORK CONTAINER", |
| 38 | Short: "Connect a container to a network", |
| 39 | Args: cli.ExactArgs(2), |
| 40 | RunE: func(cmd *cobra.Command, args []string) error { |
| 41 | options.network = args[0] |
| 42 | options.container = args[1] |
| 43 | return runConnect(cmd.Context(), dockerCLI.Client(), options) |
| 44 | }, |
| 45 | ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 46 | if len(args) == 0 { |
| 47 | return completion.NetworkNames(dockerCLI)(cmd, args, toComplete) |
| 48 | } |
| 49 | nw := args[0] |
| 50 | return completion.ContainerNames(dockerCLI, true, not(isConnected(nw)))(cmd, args, toComplete) |
| 51 | }, |
| 52 | DisableFlagsInUseLine: true, |
| 53 | } |
| 54 | |
| 55 | flags := cmd.Flags() |
| 56 | flags.IPVar(&options.ipaddress, "ip", nil, `IPv4 address (e.g., "172.30.100.104")`) |
| 57 | flags.IPVar(&options.ipv6address, "ip6", nil, `IPv6 address (e.g., "2001:db8::33")`) |
| 58 | flags.Var(&options.links, "link", "Add link to another container") |
| 59 | flags.StringSliceVar(&options.aliases, "alias", []string{}, "Add network-scoped alias for the container") |
| 60 | flags.IPSliceVar(&options.linklocalips, "link-local-ip", nil, "Add a link-local address for the container") |
| 61 | flags.StringSliceVar(&options.driverOpts, "driver-opt", []string{}, "driver options for the network") |
| 62 | flags.IntVar(&options.gwPriority, "gw-priority", 0, "Highest gw-priority provides the default gateway. Accepts positive and negative values.") |
| 63 | return cmd |
| 64 | } |
| 65 | |
| 66 | func runConnect(ctx context.Context, apiClient client.NetworkAPIClient, options connectOptions) error { |
| 67 | driverOpts, err := convertDriverOpt(options.driverOpts) |
searching dependent graphs…