@@ -2,7 +2,6 @@ namespace DotNet.Testcontainers.Containers
2
2
{
3
3
using System ;
4
4
using System . IO ;
5
- using System . Linq ;
6
5
using System . Net . Sockets ;
7
6
using System . Text ;
8
7
using System . Threading ;
@@ -130,7 +129,7 @@ await DefaultLock.WaitAsync(ct)
130
129
131
130
var requiresPrivilegedMode = TestcontainersSettings . ResourceReaperPrivilegedModeEnabled ;
132
131
133
- _defaultInstance = await GetAndStartNewAsync ( DefaultSessionId , dockerEndpointAuthConfig , resourceReaperImage , UnixSocketMount . Instance , requiresPrivilegedMode , ct : ct )
132
+ _defaultInstance = await GetAndStartNewAsync ( DefaultSessionId , dockerEndpointAuthConfig , resourceReaperImage , new UnixSocketMount ( dockerEndpointAuthConfig . Endpoint ) , requiresPrivilegedMode , ct : ct )
134
133
. ConfigureAwait ( false ) ;
135
134
136
135
return _defaultInstance ;
@@ -418,28 +417,25 @@ private sealed class UnixSocketMount : IMount
418
417
{
419
418
private const string DockerSocketFilePath = "/var/run/docker.sock" ;
420
419
421
- static UnixSocketMount ( )
420
+ public UnixSocketMount ( [ NotNull ] Uri dockerEndpoint )
422
421
{
423
- }
422
+ // If the Docker endpoint is a Unix socket, extract the socket path from the URI; otherwise, fallback to the default Unix socket path.
423
+ Source = "unix" . Equals ( dockerEndpoint . Scheme , StringComparison . OrdinalIgnoreCase ) ? dockerEndpoint . AbsolutePath : DockerSocketFilePath ;
424
424
425
- private UnixSocketMount ( )
426
- {
425
+ // If the user has overridden the Docker socket path, use the user-specified path; otherwise, keep the previously determined source.
426
+ Source = ! string . IsNullOrEmpty ( TestcontainersSettings . DockerSocketOverride ) ? TestcontainersSettings . DockerSocketOverride : Source ;
427
+ Target = DockerSocketFilePath ;
427
428
}
428
429
429
- public static IMount Instance { get ; }
430
- = new UnixSocketMount ( ) ;
431
-
432
430
public MountType Type
433
431
=> MountType . Bind ;
434
432
435
433
public AccessMode AccessMode
436
434
=> AccessMode . ReadOnly ;
437
435
438
- public string Source
439
- => TestcontainersSettings . DockerSocketOverride ?? GetSocketPath ( ) ;
436
+ public string Source { get ; }
440
437
441
- public string Target
442
- => DockerSocketFilePath ;
438
+ public string Target { get ; }
443
439
444
440
public Task CreateAsync ( CancellationToken ct = default )
445
441
{
@@ -450,12 +446,6 @@ public Task DeleteAsync(CancellationToken ct = default)
450
446
{
451
447
return Task . CompletedTask ;
452
448
}
453
-
454
- private static string GetSocketPath ( )
455
- {
456
- var dockerEndpoints = new [ ] { TestcontainersSettings . OS . DockerEndpointAuthConfig . Endpoint , UnixEndpointAuthenticationProvider . DockerEngine } ;
457
- return dockerEndpoints . First ( dockerEndpoint => "unix" . Equals ( dockerEndpoint . Scheme , StringComparison . OrdinalIgnoreCase ) ) . AbsolutePath ;
458
- }
459
449
}
460
450
}
461
451
}
0 commit comments