newPortCommand creates a new cobra.Command for "docker container port".
(dockerCLI command.Cli)
| 24 | |
| 25 | // newPortCommand creates a new cobra.Command for "docker container port". |
| 26 | func newPortCommand(dockerCLI command.Cli) *cobra.Command { |
| 27 | var opts portOptions |
| 28 | |
| 29 | cmd := &cobra.Command{ |
| 30 | Use: "port CONTAINER [PRIVATE_PORT[/PROTO]]", |
| 31 | Short: "List port mappings or a specific mapping for the container", |
| 32 | Args: cli.RequiresRangeArgs(1, 2), |
| 33 | RunE: func(cmd *cobra.Command, args []string) error { |
| 34 | opts.container = args[0] |
| 35 | if len(args) > 1 { |
| 36 | opts.port = args[1] |
| 37 | } |
| 38 | return runPort(cmd.Context(), dockerCLI, &opts) |
| 39 | }, |
| 40 | Annotations: map[string]string{ |
| 41 | "aliases": "docker container port, docker port", |
| 42 | }, |
| 43 | ValidArgsFunction: completion.ContainerNames(dockerCLI, false), |
| 44 | DisableFlagsInUseLine: true, |
| 45 | } |
| 46 | return cmd |
| 47 | } |
| 48 | |
| 49 | // runPort shows the port mapping for a given container. Optionally, it |
| 50 | // allows showing the mapping for a specific (container)port and proto. |
searching dependent graphs…