diff options
author | baude <bbaude@redhat.com> | 2018-01-22 09:17:51 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-22 17:09:11 +0000 |
commit | e1c67e6c8579931f44ec61f847f536a8f68202db (patch) | |
tree | 8afb243ad165bb0775b439ed555111e615c64ebc /cmd/podman/create.go | |
parent | 5c3e4cfa62452b9cd5c2c08bf081ab524ded1cb4 (diff) | |
download | podman-e1c67e6c8579931f44ec61f847f536a8f68202db.tar.gz podman-e1c67e6c8579931f44ec61f847f536a8f68202db.tar.bz2 podman-e1c67e6c8579931f44ec61f847f536a8f68202db.zip |
Expose ports from image
When an image has a port to expose, we need to expose it. User's input overrides the
image's port information.
Also, enable port information in ps so we can see which random port is assigned.
Signed-off-by: baude <bbaude@redhat.com>
Closes: #249
Approved by: rhatdan
Diffstat (limited to 'cmd/podman/create.go')
-rw-r--r-- | cmd/podman/create.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go index 28bd0a60e..80cb7f432 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) |