From 3c044f9267f62b8f7f88c7395ad325df3bf420f5 Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 30 Jan 2018 13:19:01 -0600 Subject: Ginkgo Tests: ps, pull, push and rm Migrate ps, pull, push, and rm from bats to ginkgo. Also, fixed a conditional issue with adding ports when an image defines the port and the user wants to override it. Signed-off-by: baude Closes: #277 Approved by: baude --- cmd/podman/create.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/podman/create.go b/cmd/podman/create.go index e0825566a..045703074 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -298,6 +298,18 @@ func isPortInPortBindings(pb map[nat.Port][]nat.PortBinding, port nat.Port) bool return libpod.StringInSlice(port.Port(), hostPorts) } +// isPortInImagePorts determines if an exposed host port was given to us by metadata +// in the image itself +func isPortInImagePorts(exposedPorts map[string]struct{}, port string) bool { + for i := range exposedPorts { + fields := strings.Split(i, "/") + if port == fields[0] { + return true + } + } + return false +} + func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error) { var exposedPorts []string var ports map[nat.Port]struct{} @@ -337,7 +349,7 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na return nil, nil, err } // check if the port in question is already being used - if isPortInPortBindings(portBindings, p) { + if isPortInPortBindings(portBindings, p) && !isPortInImagePorts(imageExposedPorts, p.Port()) { return nil, nil, errors.Errorf("host port %s already used in --publish option", p.Port()) } -- cgit v1.2.3-54-g00ecf