From affe7caf78288a638df3db37d5cebb4dc7f9ff72 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 11 Jul 2013 19:27:19 +0200 Subject: [PATCH 1/2] fix broken docker port --- commands.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index feab558259..57c258960d 100644 --- a/commands.go +++ b/commands.go @@ -574,8 +574,10 @@ func (cli *DockerCli) CmdPort(args ...string) error { return err } - if frontend, exists := out.NetworkSettings.PortMapping[cmd.Arg(1)]; exists { - fmt.Fprintf(cli.out, "%s\n", frontend) + if frontend, exists := out.NetworkSettings.PortMapping["Tcp"][cmd.Arg(1)]; exists { + fmt.Fprintf(cli.out, "tcp: %s\n", frontend) + } else if frontend, exists := out.NetworkSettings.PortMapping["Udp"][cmd.Arg(1)]; exists { + fmt.Fprintf(cli.out, "udp: %s\n", frontend) } else { return fmt.Errorf("Error: No private port '%s' allocated on %s", cmd.Arg(1), cmd.Arg(0)) } From 976428f505b64a51efbd97f71acff5db2f4f5ed0 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 11 Jul 2013 20:30:08 +0200 Subject: [PATCH 2/2] change output --- commands.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index 57c258960d..fd401a8c9c 100644 --- a/commands.go +++ b/commands.go @@ -564,6 +564,13 @@ func (cli *DockerCli) CmdPort(args ...string) error { return nil } + port := cmd.Arg(1) + proto := "Tcp" + parts := strings.SplitN(port, "/", 2) + if len(parts) == 2 && len(parts[1]) != 0 { + port = parts[0] + proto = strings.ToUpper(parts[1][:1]) + strings.ToLower(parts[1][1:]) + } body, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) if err != nil { return err @@ -574,10 +581,8 @@ func (cli *DockerCli) CmdPort(args ...string) error { return err } - if frontend, exists := out.NetworkSettings.PortMapping["Tcp"][cmd.Arg(1)]; exists { - fmt.Fprintf(cli.out, "tcp: %s\n", frontend) - } else if frontend, exists := out.NetworkSettings.PortMapping["Udp"][cmd.Arg(1)]; exists { - fmt.Fprintf(cli.out, "udp: %s\n", frontend) + if frontend, exists := out.NetworkSettings.PortMapping[proto][port]; exists { + fmt.Fprintf(cli.out, "%s\n", frontend) } else { return fmt.Errorf("Error: No private port '%s' allocated on %s", cmd.Arg(1), cmd.Arg(0)) }