@@ -135,6 +135,18 @@ public ContainerResourceBuilder Password(string password)
135135 return this ;
136136 }
137137
138+ /// <summary>
139+ /// Sets the allowed host IP address to use the external port.
140+ /// Per default all IPs are allowed (0.0.0.0).
141+ /// Example usage: if only localhost shall be allowed, then use 127.0.0.1
142+ /// </summary>
143+ /// <param name="hostIp">The allowed host IP for which the external port is exposed.</param>
144+ public ContainerResourceBuilder HostIp ( string ? hostIp )
145+ {
146+ _options . HostIp = hostIp ;
147+ return this ;
148+ }
149+
138150 /// <summary>
139151 /// Sets the main internal port of this container to the given value.
140152 ///
@@ -182,14 +194,21 @@ public ContainerResourceBuilder ExternalPort(int port)
182194 /// Only provide an external port if a static external port is required.
183195 /// When the given external port is already in use by a container, the creation will fail.
184196 /// </param>
197+ /// <param name="hostIp">
198+ /// Allowed host IP. Default all IPs are allowed
199+ /// </param>
185200 /// <returns></returns>
186- public ContainerResourceBuilder AddPortMapping ( int internalPort , int externalPort = 0 )
201+ public ContainerResourceBuilder AddPortMapping (
202+ int internalPort ,
203+ int externalPort = 0 ,
204+ string ? hostIp = null )
187205 {
188206 _options . AdditionalPortMappings . Add (
189207 new ContainerPortMapping ( )
190208 {
191209 ExternalPort = externalPort ,
192- InternalPort = internalPort
210+ InternalPort = internalPort ,
211+ HostIp = hostIp
193212 } ) ;
194213 return this ;
195214 }
@@ -208,16 +227,21 @@ public ContainerResourceBuilder AddPortMapping(int internalPort, int externalPor
208227 /// Only provide an external port if a static external port is required.
209228 /// When the given external port is already in use by a container, the creation will fail.
210229 /// </param>
230+ /// <param name="hostIp">
231+ /// Allowed host IP. Default all IPs are allowed
232+ /// </param>
211233 /// <returns></returns>
212234 public ContainerResourceBuilder AddPortMapping (
213235 int internalPort ,
214- string externalPortVariableName )
236+ string externalPortVariableName ,
237+ string ? hostIp = null )
215238 {
216239 _options . AdditionalPortMappings . Add (
217240 new ContainerPortMapping ( )
218241 {
219242 InternalPort = internalPort ,
220243 ExternalPortVariableName = externalPortVariableName ,
244+ HostIp = hostIp
221245 } ) ;
222246 return this ;
223247 }
@@ -239,16 +263,21 @@ public ContainerResourceBuilder AddPortMapping(
239263 /// Only provide an external port if a static external port is required.
240264 /// When the given external port is already in use by a container, the creation will fail.
241265 /// </param>
266+ /// <param name="hostIp">
267+ /// Allowed host IP. Default all IPs are allowed
268+ /// </param>
242269 /// <returns></returns>
243270 public ContainerResourceBuilder AddPortMapping (
244271 string internalPortVariableName ,
245- int externalPort = 0 )
272+ int externalPort = 0 ,
273+ string ? hostIp = null )
246274 {
247275 _options . AdditionalPortMappings . Add (
248276 new ContainerPortMapping ( )
249277 {
250278 InternalPortVariableName = internalPortVariableName ,
251279 ExternalPort = externalPort ,
280+ HostIp = hostIp
252281 } ) ;
253282 return this ;
254283 }
@@ -268,16 +297,21 @@ public ContainerResourceBuilder AddPortMapping(
268297 /// Only provide an external port if a static external port is required.
269298 /// When the given external port is already in use by a container, the creation will fail.
270299 /// </param>
300+ /// <param name="hostIp">
301+ /// Allowed host IP. Default all IPs are allowed
302+ /// </param>
271303 /// <returns></returns>
272304 public ContainerResourceBuilder AddPortMapping (
273305 string internalPortVariableName ,
274- string externalPortVariableName )
306+ string externalPortVariableName ,
307+ string ? hostIp = null )
275308 {
276309 _options . AdditionalPortMappings . Add (
277310 new ContainerPortMapping ( )
278311 {
279312 InternalPortVariableName = internalPortVariableName ,
280- ExternalPortVariableName = externalPortVariableName
313+ ExternalPortVariableName = externalPortVariableName ,
314+ HostIp = hostIp
281315 } ) ;
282316 return this ;
283317 }
0 commit comments