diff --git a/api_params.go b/api_params.go index 897eb660d..e036f34cc 100644 --- a/api_params.go +++ b/api_params.go @@ -42,6 +42,7 @@ type APIRmi struct { } type APIContainers struct { + Name string ID string `json:"Id"` Image string Command string diff --git a/commands.go b/commands.go index 36826fc4b..fe18257ba 100644 --- a/commands.go +++ b/commands.go @@ -1074,7 +1074,7 @@ func (cli *DockerCli) CmdPs(args ...string) error { } w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) if !*quiet { - fmt.Fprint(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS") + fmt.Fprint(w, "NAME\tID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS") if *size { fmt.Fprintln(w, "\tSIZE") } else { @@ -1085,9 +1085,9 @@ func (cli *DockerCli) CmdPs(args ...string) error { for _, out := range outs { if !*quiet { if *noTrunc { - fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", out.ID, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, displayablePorts(out.Ports)) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\t%s\t", out.Name, out.ID, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, displayablePorts(out.Ports)) } else { - fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t", utils.TruncateID(out.ID), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, displayablePorts(out.Ports)) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\t%s\t", out.Name, utils.TruncateID(out.ID), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, displayablePorts(out.Ports)) } if *size { if out.SizeRootFs > 0 { diff --git a/links.go b/links.go index e44c07319..cd70f7231 100644 --- a/links.go +++ b/links.go @@ -42,7 +42,7 @@ func (r *LinkRepository) NewLink(to, from *Container, bridgeInterface string, al FromID: utils.TruncateID(from.ID), ToID: utils.TruncateID(to.ID), BridgeInterface: bridgeInterface, - Alias: strings.ToUpper(alias), + Alias: alias, FromIP: from.NetworkSettings.IPAddress, ToIP: to.NetworkSettings.IPAddress, FromEnvironment: from.Config.Env, @@ -67,7 +67,7 @@ func (l *Link) ToEnv() []string { // Load exposed ports into the environment for _, p := range l.Ports { - env = append(env, fmt.Sprintf("%s_PORT_%s_%s=%s://%s:%s", l.Alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto(), l.FromIP, p.Port())) + env = append(env, fmt.Sprintf("%s_PORT_%s_%s=%s://%s:%s", l.Alias, p.Port(), p.Proto(), p.Proto(), l.FromIP, p.Port())) } // Load the linked container's ID into the environment @@ -100,7 +100,7 @@ func (l *Link) getDefaultPort() *Port { sortPorts(l.Ports, func(ip, jp Port) bool { // If the two ports have the same number, tcp takes priority // Sort in desc order - return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp") + return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && strings.ToLower(ip.Proto()) == "tcp") }) } p = l.Ports[0] diff --git a/server.go b/server.go index 8322e8e65..c90ded544 100644 --- a/server.go +++ b/server.go @@ -357,7 +357,7 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) { func (srv *Server) Containers(all, size bool, n int, since, before string) []APIContainers { var foundBefore bool var displayed int - retContainers := []APIContainers{} + retContainers := make(map[string]APIContainers) for _, container := range srv.runtime.List() { if !container.State.Running && !all && n == -1 && since == "" && before == "" { @@ -383,6 +383,8 @@ func (srv *Server) Containers(all, size bool, n int, since, before string) []API c := APIContainers{ ID: container.ID, } + c.Name = utils.TruncateID(container.ID) + c.Image = srv.runtime.repositories.ImageName(container.Image) c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " ")) c.Created = container.Created.Unix() @@ -391,9 +393,23 @@ func (srv *Server) Containers(all, size bool, n int, since, before string) []API if size { c.SizeRw, c.SizeRootFs = container.GetSize() } - retContainers = append(retContainers, c) + retContainers[utils.TruncateID(c.ID)] = c } - return retContainers + out := make([]APIContainers, len(retContainers)) + var i int + for _, v := range retContainers { + out[i] = v + i++ + } + + // Add links to result + for _, link := range srv.runtime.links.GetAll() { + cp := retContainers[link.ToID] + c := cp + c.Name = fmt.Sprintf("%s/%s", link.FromID, link.Alias) + out = append(out, c) + } + return out } func (srv *Server) ContainerCommit(name, repo, tag, author, comment string, config *Config) (string, error) {