mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-10-16 19:07:45 +00:00
Merge pull request #7201 from mheon/0000_is_empty
Do not set host IP on ports when 0.0.0.0 requested
This commit is contained in:
commit
1ed1e583a0
4 changed files with 24 additions and 6 deletions
|
|
@ -175,12 +175,15 @@ func parseSplitPort(hostIP, hostPort *string, ctrPort string, protocol *string)
|
|||
if hostIP != nil {
|
||||
if *hostIP == "" {
|
||||
return newPort, errors.Errorf("must provide a non-empty container host IP to publish")
|
||||
} else if *hostIP != "0.0.0.0" {
|
||||
// If hostIP is 0.0.0.0, leave it unset - CNI treats
|
||||
// 0.0.0.0 and empty differently, Docker does not.
|
||||
testIP := net.ParseIP(*hostIP)
|
||||
if testIP == nil {
|
||||
return newPort, errors.Errorf("cannot parse %q as an IP address", *hostIP)
|
||||
}
|
||||
newPort.HostIP = testIP.String()
|
||||
}
|
||||
testIP := net.ParseIP(*hostIP)
|
||||
if testIP == nil {
|
||||
return newPort, errors.Errorf("cannot parse %q as an IP address", *hostIP)
|
||||
}
|
||||
newPort.HostIP = testIP.String()
|
||||
}
|
||||
if hostPort != nil {
|
||||
if *hostPort == "" {
|
||||
|
|
|
|||
|
|
@ -634,7 +634,8 @@ Both hostPort and containerPort can be specified as a range of ports.
|
|||
When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range.
|
||||
(e.g., `podman run -p 1234-1236:1222-1224 --name thisWorks -t busybox`
|
||||
but not `podman run -p 1230-1236:1230-1240 --name RangeContainerPortsBiggerThanRangeHostPorts -t busybox`)
|
||||
With ip: `podman run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage`
|
||||
With host IP: `podman run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage`
|
||||
If host IP is set to 0.0.0.0 or not set at all, the port will be bound on all IPs on the host.
|
||||
Host port does not have to be specified (e.g. `podman run -p 127.0.0.1::80`).
|
||||
If it is not, the container port will be randomly assigned a port on the host.
|
||||
Use `podman port` to see the actual mapping: `podman port CONTAINER $CONTAINERPORT`
|
||||
|
|
|
|||
|
|
@ -647,6 +647,8 @@ Both hostPort and containerPort can be specified as a range of ports.
|
|||
|
||||
When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range.
|
||||
|
||||
If host IP is set to 0.0.0.0 or not set at all, the port will be bound on all IPs on the host.
|
||||
|
||||
Host port does not have to be specified (e.g. `podman run -p 127.0.0.1::80`).
|
||||
If it is not, the container port will be randomly assigned a port on the host.
|
||||
|
||||
|
|
|
|||
|
|
@ -236,6 +236,18 @@ var _ = Describe("Podman run networking", func() {
|
|||
Expect((hp1 == "4000" && hp2 == "8000") || (hp1 == "8000" && hp2 == "4000")).To(BeTrue())
|
||||
})
|
||||
|
||||
It("podman run -p 0.0.0.0:8080:80", func() {
|
||||
name := "testctr"
|
||||
session := podmanTest.Podman([]string{"create", "-t", "-p", "0.0.0.0:8080:80", "--name", name, ALPINE, "/bin/sh"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
inspectOut := podmanTest.InspectContainer(name)
|
||||
Expect(len(inspectOut)).To(Equal(1))
|
||||
Expect(len(inspectOut[0].NetworkSettings.Ports)).To(Equal(1))
|
||||
Expect(len(inspectOut[0].NetworkSettings.Ports["80/tcp"])).To(Equal(1))
|
||||
Expect(inspectOut[0].NetworkSettings.Ports["80/tcp"][0].HostPort).To(Equal("8080"))
|
||||
Expect(inspectOut[0].NetworkSettings.Ports["80/tcp"][0].HostIP).To(Equal(""))
|
||||
})
|
||||
|
||||
It("podman run network expose host port 80 to container port 8000", func() {
|
||||
SkipIfRootless()
|
||||
session := podmanTest.Podman([]string{"run", "-dt", "-p", "80:8000", ALPINE, "/bin/sh"})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue