diff options
Diffstat (limited to 'cmd/podman/create.go')
-rw-r--r-- | cmd/podman/create.go | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go index 28bd0a60e..e0825566a 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -299,15 +299,26 @@ func isPortInPortBindings(pb map[nat.Port][]nat.PortBinding, port nat.Port) bool } func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error) { - // TODO Handle exposed ports from image - // Currently ignoring imageExposedPorts + var exposedPorts []string var ports map[nat.Port]struct{} ports = make(map[nat.Port]struct{}) _, portBindings, err := nat.ParsePortSpecs(c.StringSlice("publish")) if err != nil { return nil, nil, err } - for _, e := range c.StringSlice("expose") { + + // Parse the ports from the image itself + for i := range imageExposedPorts { + fields := strings.Split(i, "/") + if len(fields) > 2 { + return nil, nil, errors.Errorf("invalid exposed port format in image") + } + exposedPorts = append(exposedPorts, fields[0]) + } + + // Add the ports from the image to the ports from the user + exposedPorts = append(exposedPorts, c.StringSlice("expose")...) + for _, e := range exposedPorts { // Merge in exposed ports to the map of published ports if strings.Contains(e, ":") { return nil, nil, fmt.Errorf("invalid port format for --expose: %s", e) @@ -359,10 +370,13 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na // default container runtime data out of it. imageData returns the data // to the caller. Example Data: Entrypoint, Env, WorkingDir, Labels ... func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *libpod.ImageData, error) { - var err error + var ( + err error + imageName, imageID string + ) // Deal with the image after all the args have been checked createImage := runtime.NewImage(image) - createImage.LocalName, _ = createImage.GetLocalImageName() + imageName, imageID, _ = createImage.GetLocalImageName() if createImage.LocalName == "" { // The image wasnt found by the user input'd name or its fqname // Pull the image @@ -373,31 +387,14 @@ func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, s createImage.Pull(writer) } - var imageName string - if createImage.LocalName != "" { - nameIsID, err := runtime.IsImageID(createImage.LocalName) - if err != nil { - return "", "", nil, err - } - if nameIsID { - // If the input from the user is an ID, then we need to get the image - // name for cstorage - createImage.LocalName, err = createImage.GetNameByID() - if err != nil { - return "", "", nil, err - } - } - imageName = createImage.LocalName - } else { + createImage.LocalName = imageName + if imageName == "" { imageName, err = createImage.GetFQName() + _, imageID, _ = createImage.GetLocalImageName() } if err != nil { return "", "", nil, err } - imageID, err := createImage.GetImageID() - if err != nil { - return "", "", nil, err - } storageImage, err := runtime.GetImage(imageName) if err != nil { return "", "", nil, errors.Wrapf(err, "error getting storage image %q", image) |