Skip to content

Commit

Permalink
Added support for udp protocol.
Browse files Browse the repository at this point in the history
Added protocol parameter with tcp as default
in ExposePort builder function. This can be used to
pass "udp" instead to expose UDP ports.
  • Loading branch information
mariotoffia committed Mar 24, 2021
1 parent edb68ed commit 21e3e93
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions Ductus.FluentDocker/Builders/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override IContainerService Build()
{
_config.CreateParams.Network = firstNetwork.Network;

if(string.Empty != firstNetwork.Alias)
if (string.Empty != firstNetwork.Alias)
{
_config.CreateParams.Alias = firstNetwork.Alias;
}
Expand Down Expand Up @@ -259,9 +259,21 @@ public ContainerBuilder UseDnsOption(params string[] option)
return this;
}

public ContainerBuilder ExposePort(int hostPort, int containerPort)
public ContainerBuilder ExposePort(int hostPort, int containerPort, string protocol = "tcp")
{
_config.CreateParams.PortMappings = _config.CreateParams.PortMappings.ArrayAdd($"{hostPort}:{containerPort}");
if (string.IsNullOrEmpty(protocol))
{
protocol = "tcp";
}

if (protocol.ToLower() == "tcp")
{
_config.CreateParams.PortMappings = _config.CreateParams.PortMappings.ArrayAdd($"{hostPort}:{containerPort}");
}
else
{
_config.CreateParams.PortMappings = _config.CreateParams.PortMappings.ArrayAdd($"{hostPort}:{containerPort}/{protocol}");
}
return this;
}

Expand Down Expand Up @@ -474,13 +486,13 @@ public ContainerBuilder UseNetworksWithAlias(string alias, params INetworkServic
_config.NetworksWithAlias = new List<NetworkWithAlias<INetworkService>>();


foreach(var network in networks)
foreach (var network in networks)
{
_config.NetworksWithAlias.Add(new NetworkWithAlias<INetworkService>
{
Network = network,
Alias = alias
});
{
Network = network,
Alias = alias
});
}

return this;
Expand Down

0 comments on commit 21e3e93

Please sign in to comment.