newAttachCommand creates a new cobra.Command for `docker attach`
(dockerCLI command.Cli)
| 42 | |
| 43 | // newAttachCommand creates a new cobra.Command for `docker attach` |
| 44 | func newAttachCommand(dockerCLI command.Cli) *cobra.Command { |
| 45 | var opts AttachOptions |
| 46 | |
| 47 | cmd := &cobra.Command{ |
| 48 | Use: "attach [OPTIONS] CONTAINER", |
| 49 | Short: "Attach local standard input, output, and error streams to a running container", |
| 50 | Args: cli.ExactArgs(1), |
| 51 | RunE: func(cmd *cobra.Command, args []string) error { |
| 52 | containerID := args[0] |
| 53 | return RunAttach(cmd.Context(), dockerCLI, containerID, &opts) |
| 54 | }, |
| 55 | Annotations: map[string]string{ |
| 56 | "aliases": "docker container attach, docker attach", |
| 57 | }, |
| 58 | ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr container.Summary) bool { |
| 59 | return ctr.State != container.StatePaused |
| 60 | }), |
| 61 | DisableFlagsInUseLine: true, |
| 62 | } |
| 63 | |
| 64 | flags := cmd.Flags() |
| 65 | flags.BoolVar(&opts.NoStdin, "no-stdin", false, "Do not attach STDIN") |
| 66 | flags.BoolVar(&opts.Proxy, "sig-proxy", true, "Proxy all received signals to the process") |
| 67 | flags.StringVar(&opts.DetachKeys, "detach-keys", "", "Override the key sequence for detaching a container") |
| 68 | return cmd |
| 69 | } |
| 70 | |
| 71 | // RunAttach executes an `attach` command |
| 72 | func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, opts *AttachOptions) error { |
searching dependent graphs…