pub struct PortMapping {
pub container_port: u16,
pub host_port: Option<u16>,
pub host_ip: IpAddr,
pub protocol: Protocol,
}Expand description
One container port published to the host (docker run -p).
Safe by default: bound to loopback (127.0.0.1). The host port is
None (dockerd picks a free ephemeral port; read it back with
Lifecycle::published_host_port) unless PortMapping::with_host_port
pins it. A 1:1 mapping is
PortMapping::tcp(p).with_host_port(p).
Fields§
§container_port: u16§host_port: Option<u16>None lets dockerd allocate a free host port.
host_ip: IpAddr§protocol: ProtocolImplementations§
Source§impl PortMapping
impl PortMapping
Sourcepub fn tcp(container_port: u16) -> Self
pub fn tcp(container_port: u16) -> Self
Publish TCP container_port on loopback with a dockerd-allocated
host port.
Sourcepub fn udp(container_port: u16) -> Self
pub fn udp(container_port: u16) -> Self
As PortMapping::tcp but UDP.
pub fn with_host_port(self, host_port: u16) -> Self
Sourcepub fn with_host_ip(self, host_ip: IpAddr) -> Self
pub fn with_host_ip(self, host_ip: IpAddr) -> Self
Bind on a specific host interface. 0.0.0.0 exposes the port to the
LAN — an explicit, reviewable choice, never the default.
Trait Implementations§
Source§impl Clone for PortMapping
impl Clone for PortMapping
Source§impl Debug for PortMapping
impl Debug for PortMapping
impl Eq for PortMapping
Source§impl PartialEq for PortMapping
impl PartialEq for PortMapping
impl StructuralPartialEq for PortMapping
Auto Trait Implementations§
impl Forget for PortMapping
impl Freeze for PortMapping
impl Move for PortMapping
impl RefUnwindSafe for PortMapping
impl Send for PortMapping
impl Sync for PortMapping
impl Unpin for PortMapping
impl UnsafeUnpin for PortMapping
impl UnwindSafe for PortMapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more