diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 26a9e128f..ca717abaa 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -418,8 +418,8 @@ func checkPortStats(ports []dto.PortHelper) (nat.PortMap, error) { return portMap, nil } for _, port := range ports { - if strings.Contains(port.HostPort, "-") { - if !strings.Contains(port.ContainerPort, "-") { + if strings.Contains(port.ContainerPort, "-") { + if !strings.Contains(port.HostPort, "-") { return portMap, buserr.New(constant.ErrPortRules) } hostStart, _ := strconv.Atoi(strings.Split(port.HostPort, "-")[0]) @@ -442,7 +442,12 @@ func checkPortStats(ports []dto.PortHelper) (nat.PortMap, error) { } } } else { - portItem, _ := strconv.Atoi(port.HostPort) + portItem := 0 + if strings.Contains(port.HostPort, "-") { + portItem, _ = strconv.Atoi(strings.Split(port.HostPort, "-")[0]) + } else { + portItem, _ = strconv.Atoi(port.HostPort) + } if common.ScanPort(portItem) { return portMap, buserr.WithDetail(constant.ErrPortInUsed, portItem, nil) } diff --git a/frontend/src/views/container/container/create/index.vue b/frontend/src/views/container/container/create/index.vue index 51cdf4e3d..2ef9daf66 100644 --- a/frontend/src/views/container/container/create/index.vue +++ b/frontend/src/views/container/container/create/index.vue @@ -58,7 +58,7 @@ - +