ContainerNetworkOptions Class

Network options for a container.

public sealed class ContainerNetworkOptions

Remarks

A container joins ContainerNetworkOptions.Network first, when it is set, then every network added with ContainerNetworkOptions.Add or ContainerNetworkOptions.Add, in order.

Properties

NameDescription
AliasGets or sets a network alias for the container on ContainerNetworkOptions.Network, or on the default network when ContainerNetworkOptions.Network is not set.
AttachmentsGets the networks added with ContainerNetworkOptions.Add and ContainerNetworkOptions.Add.
NetworkGets or sets the network the container connects to first. It can also be a network mode, such as host or none.

Gets or sets a network alias for the container on ContainerNetworkOptions.Network, or on the default network when ContainerNetworkOptions.Network is not set.

public string? Alias { get; set; }

Property value

string?

Gets or sets the network the container connects to first. It can also be a network mode, such as host or none.

public string? Network { get; set; }

Property value

string?

Methods

NameDescription
Add(TemporaryNetwork, string[])Connects the container to a TemporaryNetwork. The network is created, if needed, when the container is created.
Add(string, string[])Connects the container to an existing network.
Remove(string)Disconnects the container from a network added with ContainerNetworkOptions.Add or ContainerNetworkOptions.Add.

Add overloads

Add(TemporaryNetwork, string[])

ContainerNetworkOptions.cs

Connects the container to a TemporaryNetwork. The network is created, if needed, when the container is created.

public void Add(TemporaryNetwork network, params string[] aliases)
Parameters
network TemporaryNetwork
The network.
aliases string[]
The aliases the other containers of the network reach the container by.
Exceptions
ArgumentException
The container already joins the network.

Add(string, string[])

ContainerNetworkOptions.cs

Connects the container to an existing network.

public void Add(string network, params string[] aliases)
Parameters
network string
The name of the network.
aliases string[]
The aliases the other containers of the network reach the container by.
Exceptions
ArgumentException
The container already joins the network.

Disconnects the container from a network added with ContainerNetworkOptions.Add or ContainerNetworkOptions.Add.

public bool Remove(string network)

Parameters

network string
The name of the network.

Returns

bool true if the network was removed; otherwise, false.