|
@@ -27,12 +27,26 @@ const (
|
|
|
DefaultDockerfileName string = "Dockerfile"
|
|
|
)
|
|
|
|
|
|
-// byPrivatePort is temporary type used to sort types.Port by PrivatePort
|
|
|
-type byPrivatePort []types.Port
|
|
|
+// byPortInfo is a temporary type used to sort types.Port by its fields
|
|
|
+type byPortInfo []types.Port
|
|
|
|
|
|
-func (r byPrivatePort) Len() int { return len(r) }
|
|
|
-func (r byPrivatePort) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
|
|
-func (r byPrivatePort) Less(i, j int) bool { return r[i].PrivatePort < r[j].PrivatePort }
|
|
|
+func (r byPortInfo) Len() int { return len(r) }
|
|
|
+func (r byPortInfo) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
|
|
+func (r byPortInfo) Less(i, j int) bool {
|
|
|
+ if r[i].PrivatePort != r[j].PrivatePort {
|
|
|
+ return r[i].PrivatePort < r[j].PrivatePort
|
|
|
+ }
|
|
|
+
|
|
|
+ if r[i].IP != r[j].IP {
|
|
|
+ return r[i].IP < r[j].IP
|
|
|
+ }
|
|
|
+
|
|
|
+ if r[i].PublicPort != r[j].PublicPort {
|
|
|
+ return r[i].PublicPort < r[j].PublicPort
|
|
|
+ }
|
|
|
+
|
|
|
+ return r[i].Type < r[j].Type
|
|
|
+}
|
|
|
|
|
|
// DisplayablePorts returns formatted string representing open ports of container
|
|
|
// e.g. "0.0.0.0:80->9090/tcp, 9988/tcp"
|
|
@@ -45,7 +59,8 @@ func DisplayablePorts(ports []types.Port) string {
|
|
|
groupMap := make(map[string]*portGroup)
|
|
|
var result []string
|
|
|
var hostMappings []string
|
|
|
- sort.Sort(byPrivatePort(ports))
|
|
|
+ var groupMapKeys []string
|
|
|
+ sort.Sort(byPortInfo(ports))
|
|
|
for _, port := range ports {
|
|
|
current := port.PrivatePort
|
|
|
portKey := port.Type
|
|
@@ -60,6 +75,8 @@ func DisplayablePorts(ports []types.Port) string {
|
|
|
|
|
|
if group == nil {
|
|
|
groupMap[portKey] = &portGroup{first: current, last: current}
|
|
|
+ // record order that groupMap keys are created
|
|
|
+ groupMapKeys = append(groupMapKeys, portKey)
|
|
|
continue
|
|
|
}
|
|
|
if current == (group.last + 1) {
|
|
@@ -70,7 +87,8 @@ func DisplayablePorts(ports []types.Port) string {
|
|
|
result = append(result, formGroup(portKey, group.first, group.last))
|
|
|
groupMap[portKey] = &portGroup{first: current, last: current}
|
|
|
}
|
|
|
- for portKey, g := range groupMap {
|
|
|
+ for _, portKey := range groupMapKeys {
|
|
|
+ g := groupMap[portKey]
|
|
|
result = append(result, formGroup(portKey, g.first, g.last))
|
|
|
}
|
|
|
result = append(result, hostMappings...)
|