From b4d64bf2a6f5471df34a8432409425e854b77b48 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 13 Dec 2023 10:30:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E5=8A=A0=E8=BD=BD=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#3295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/container.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index d598f3772..3775f131b 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -1059,13 +1059,19 @@ func simplifyPort(ports []types.Port) []string { if start.PublicPort != 0 { itemPortStr = fmt.Sprintf("%s:%v->%v/%s", start.IP, start.PublicPort, start.PrivatePort, start.Type) } - datas = append(datas, strings.TrimPrefix(itemPortStr, ":")) + if len(start.IP) == 0 { + itemPortStr = strings.TrimPrefix(itemPortStr, ":") + } + datas = append(datas, itemPortStr) } else { itemPortStr := fmt.Sprintf("%s:%v-%v/%s", start.IP, start.PrivatePort, ports[i-1].PrivatePort, start.Type) if start.PublicPort != 0 { itemPortStr = fmt.Sprintf("%s:%v-%v->%v-%v/%s", start.IP, start.PublicPort, ports[i-1].PublicPort, start.PrivatePort, ports[i-1].PrivatePort, start.Type) } - datas = append(datas, strings.TrimPrefix(itemPortStr, ":")) + if len(start.IP) == 0 { + itemPortStr = strings.TrimPrefix(itemPortStr, ":") + } + datas = append(datas, itemPortStr) } start = ports[i] } @@ -1075,13 +1081,19 @@ func simplifyPort(ports []types.Port) []string { if start.PublicPort != 0 { itemPortStr = fmt.Sprintf("%s:%v->%v/%s", start.IP, start.PublicPort, start.PrivatePort, start.Type) } - datas = append(datas, strings.TrimPrefix(itemPortStr, ":")) + if len(start.IP) == 0 { + itemPortStr = strings.TrimPrefix(itemPortStr, ":") + } + datas = append(datas, itemPortStr) } else { itemPortStr := fmt.Sprintf("%s:%v-%v/%s", start.IP, start.PrivatePort, ports[i].PrivatePort, start.Type) if start.PublicPort != 0 { itemPortStr = fmt.Sprintf("%s:%v-%v->%v-%v/%s", start.IP, start.PublicPort, ports[i].PublicPort, start.PrivatePort, ports[i].PrivatePort, start.Type) } - datas = append(datas, strings.TrimPrefix(itemPortStr, ":")) + if len(start.IP) == 0 { + itemPortStr = strings.TrimPrefix(itemPortStr, ":") + } + datas = append(datas, itemPortStr) } } }