ContainerPort Class
Represents a container port that is published to the host.
public sealed class ContainerPort : IEquatable<ContainerPort>- Implements
Constructors
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the ContainerPort class that binds to a random host port.
public ContainerPort(int containerPort)Parameters
containerPortint- The port exposed inside the container.
ContainerPort(int?, int)
ContainerPort.csProperties
| Name | Description |
|---|---|
| HostIp | 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. |
| HostPort | Gets the host port to bind, or null to let the runtime assign a random host port. |
| Port | Gets the port exposed inside the container. |
| Protocol | Gets the transport protocol of the port. Defaults to ContainerPortProtocol.Tcp. |
HostIp
ContainerPort.csGets 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
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.
HostPort
ContainerPort.csPort
ContainerPort.csProtocol
ContainerPort.csGets the transport protocol of the port. Defaults to ContainerPortProtocol.Tcp.
public ContainerPortProtocol Protocol { get; init; }Property value
Remarks
A container port is published once, whatever its protocol: publishing it for both TCP and UDP is not supported.
Methods
| Name | Description |
|---|---|
| Deconstruct(int?, int) | |
| Equals(ContainerPort?) | |
| Equals(object?) | |
| GetHashCode() | |
| ToString() |
Deconstruct(int?, int)
Equals overloads
Equals(ContainerPort?)
public bool Equals(ContainerPort? other)No documentation is available.
Equals(object?)
GetHashCode()
ToString()
Operators
| Name | Description |
|---|---|
| operator ==(ContainerPort?, ContainerPort?) | |
| operator !=(ContainerPort?, ContainerPort?) |
operator ==(ContainerPort?, ContainerPort?)
public static bool operator ==(ContainerPort? left, ContainerPort? right)No documentation is available.
operator !=(ContainerPort?, ContainerPort?)
public static bool operator !=(ContainerPort? left, ContainerPort? right)No documentation is available.
Constants
| Name | Description |
|---|---|
| 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. |
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"