ContainerPort Class

Represents a container port that is published to the host.

public sealed class ContainerPort : IEquatable<ContainerPort>
Implements

Constructors

NameDescription
ContainerPort(int)Initializes a new instance of the ContainerPort class that binds to a random host port.
ContainerPort(int?, int)Represents a container port that is published to the host.

ContainerPort overloads

ContainerPort(int)

ContainerPort.cs

Initializes a new instance of the ContainerPort class that binds to a random host port.

public ContainerPort(int containerPort)
Parameters
containerPort int
The port exposed inside the container.

ContainerPort(int?, int)

ContainerPort.cs

Represents a container port that is published to the host.

public ContainerPort(int? HostPort, int Port)
Parameters
HostPort int?
The host port to bind, or null to let the runtime assign a random host port.
Port int
The port exposed inside the container.

Properties

NameDescription
HostIpGets the host address the port is published on. Defaults to ContainerPort.DefaultHostIp, so a test database is not reachable from the network; use 0.0.0.0 to publish the port on every interface.
HostPortGets the host port to bind, or null to let the runtime assign a random host port.
PortGets the port exposed inside the container.
ProtocolGets the transport protocol of the port. Defaults to ContainerPortProtocol.Tcp.

Gets the host address the port is published on. Defaults to ContainerPort.DefaultHostIp, so a test database is not reachable from the network; use 0.0.0.0 to publish the port on every interface.

public string HostIp { get; init; }

Property value

string

Remarks

Windows containers cannot be published on a specific address, and wslc publishes through the loopback forwarding of WSL, so the address is not passed to them.

Gets the host port to bind, or null to let the runtime assign a random host port.

public int? HostPort { get; init; }

Property value

int?

Gets the port exposed inside the container.

public int Port { get; init; }

Property value

int

Gets the transport protocol of the port. Defaults to ContainerPortProtocol.Tcp.

public ContainerPortProtocol Protocol { get; init; }

Property value

ContainerPortProtocol

Remarks

A container port is published once, whatever its protocol: publishing it for both TCP and UDP is not supported.

Methods

NameDescription
Deconstruct(int?, int)
Equals(ContainerPort?)
Equals(object?)
GetHashCode()
ToString()

Deconstruct(int?, int)

public void Deconstruct(out int? HostPort, out int Port)

Parameters

HostPort int?
Port int

No documentation is available.

Equals overloads

Equals(ContainerPort?)

public bool Equals(ContainerPort? other)
Parameters
other ContainerPort?
Returns

bool

No documentation is available.

Equals(object?)

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

public override int GetHashCode()

Returns

int

No documentation is available.

ToString()

public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(ContainerPort?, ContainerPort?)
operator !=(ContainerPort?, ContainerPort?)

operator ==(ContainerPort?, ContainerPort?)

public static bool operator ==(ContainerPort? left, ContainerPort? right)

Parameters

left ContainerPort?
right ContainerPort?

Returns

bool

No documentation is available.

operator !=(ContainerPort?, ContainerPort?)

public static bool operator !=(ContainerPort? left, ContainerPort? right)

Parameters

left ContainerPort?
right ContainerPort?

Returns

bool

No documentation is available.

Constants

NameDescription
DefaultHostIpThe host address a port is published on unless ContainerPort.HostIp says otherwise: the loopback address, so the container is only reachable from this machine.

DefaultHostIp

The host address a port is published on unless ContainerPort.HostIp says otherwise: the loopback address, so the container is only reachable from this machine.

public const string DefaultHostIp = "127.0.0.1"