testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.82k stars 278 forks source link

[Bug]: Testcontainers not finding the docker daemon #1285

Closed 123Inge closed 2 weeks ago

123Inge commented 3 weeks ago

Testcontainers version

3.10.0

Using the latest Testcontainers version?

Yes

Host OS

macOS Ventura 13.4

Host arch

ARM - (M2 PRO chip)

.NET version

8.0

Docker version

Client: Version: 24.0.6-rd API version: 1.43 Go version: go1.20.7 Git commit: da4c87c Built: Wed Sep 6 16:40:13 2023 OS/Arch: darwin/arm64 Context: orbstack

Server: Docker Engine - Community Engine: Version: 27.3.1 API version: 1.47 (minimum version 1.24) Go version: go1.22.7 Git commit: 41ca978 Built: Fri Sep 20 11:39:57 2024 OS/Arch: linux/arm64 Experimental: false containerd: Version: v1.7.22 GitCommit: 7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c runc: Version: 1.1.14 GitCommit: 2c9f5602f0ba3d9da1c2596322dfc4e156844890 docker-init: Version: 0.19.0 GitCommit: de40ad0

Docker info

Client: Version: 24.0.6-rd Context: orbstack Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.17.1 Path: /Users/myname/.docker/cli-plugins/docker-buildx compose: Docker Compose (Docker Inc.) Version: v2.29.7 Path: /Users/myname/.docker/cli-plugins/docker-compose

Server: Containers: 29 Running: 2 Paused: 0 Stopped: 27 Images: 47 Server Version: 27.3.1 Storage Driver: overlay2 Backing Filesystem: btrfs Supports d_type: true Using metacopy: false Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 runc Default Runtime: runc Init Binary: docker-init containerd version: 7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c runc version: 2c9f5602f0ba3d9da1c2596322dfc4e156844890 init version: de40ad0 Security Options: seccomp Profile: builtin cgroupns Kernel Version: 6.10.12-orbstack-00282-gd1783374c25e Operating System: OrbStack OSType: linux Architecture: aarch64 CPUs: 10 Total Memory: 9.763GiB Name: orbstack ID: e79dd471-301b-4e7a-9f68-1a0d177ec109 Docker Root Dir: /var/lib/docker Debug Mode: false Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false Product License: Community Engine Default Address Pools: Base: 192.168.97.0/24, Size: 24 Base: 192.168.107.0/24, Size: 24 Base: 192.168.117.0/24, Size: 24 Base: 192.168.147.0/24, Size: 24 Base: 192.168.148.0/24, Size: 24 Base: 192.168.155.0/24, Size: 24 Base: 192.168.156.0/24, Size: 24 Base: 192.168.158.0/24, Size: 24 Base: 192.168.163.0/24, Size: 24 Base: 192.168.164.0/24, Size: 24 Base: 192.168.165.0/24, Size: 24 Base: 192.168.166.0/24, Size: 24 Base: 192.168.167.0/24, Size: 24 Base: 192.168.171.0/24, Size: 24 Base: 192.168.172.0/24, Size: 24 Base: 192.168.181.0/24, Size: 24 Base: 192.168.183.0/24, Size: 24 Base: 192.168.186.0/24, Size: 24 Base: 192.168.207.0/24, Size: 24 Base: 192.168.214.0/24, Size: 24 Base: 192.168.215.0/24, Size: 24 Base: 192.168.216.0/24, Size: 24 Base: 192.168.223.0/24, Size: 24 Base: 192.168.227.0/24, Size: 24 Base: 192.168.228.0/24, Size: 24 Base: 192.168.229.0/24, Size: 24 Base: 192.168.237.0/24, Size: 24 Base: 192.168.239.0/24, Size: 24 Base: 192.168.242.0/24, Size: 24 Base: 192.168.247.0/24, Size: 24

What happened?

Both in Jetbrains Rider and in terminal, when I run dotnet test or run tests from inside Rider I get the this error:

System.ArgumentException: Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly config...

System.ArgumentException
Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/ (Parameter 'DockerEndpointAuthConfig')
   at DotNet.Testcontainers.Guard.ThrowIf[TType](ArgumentInfo`1& argument, Func`2 condition, Func`2 ifClause) in /_/src/Testcontainers/Guard.Null.cs:line 62
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 145
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at tests.Setup.PostGISContainer..ctor(TestSettings testSettings) in /Users/myname/someproject/tests/Setup/PostGISContainer.cs:line 27
   at InvokeStub_PostGISContainer..ctor(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at App.Program.Main(String[] args) in /Users/ingehegge/Documents/VOLUE/spark-grid/src/App/Program.cs:line 81
   at InvokeStub_Program.Main(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.DeferredHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateHost(IHostBuilder builder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.get_Services()
   at tests.someproject in /Users/myname/someproject/tests/Location/LocationStorageServiceTest.cs:line 16
   at InvokeStub_LocationStorageServiceTest..ctor(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Relevant log output

No response

Additional information

I have tried the normal stuff, restarting docker, Rider and the mac. I have tried to change the docker contexts, no difference. I have tried the equivalent of this. I know that is for Java and Colima and not dotnet and Orbstack, but I could not find the similar problem with Orbstack.

By a recommendation by a colleague, I tried to make the file ~/.testcontainers.properties containing the information:

docker.socket.override=/var/run/docker.sock
docker.host=unix:///Users/myname/.orbstack/default/docker.sock

or

docker.socket.override=/var/run/docker.sock
docker.host=unix:///Users/myname/.orbstack/run/docker.sock

but this also made no difference (one of them got another error: Hosting failed to start | System.Net.Http.HttpRequestException: Connection failed). I probably left out a bunch of important information here, but I am not sure how to make bug-reports like this (sorry). I have the newest version of Orbstack (1.7.5), if that is any helpful.

In advance, thanks for any help.

HofmeisterAn commented 3 weeks ago

Hi 👋 thanks for raising the issue. Could you please try the develop branch? Recently, we updated it to read the endpoint from the context. The author of https://github.com/testcontainers/testcontainers-dotnet/pull/1235 tested it with Colima and OrbStack.

123Inge commented 3 weeks ago

Dumb question: how do I use the develop branch? Is that a nuget package?

HofmeisterAn commented 3 weeks ago

Sorry, there is no NuGet package available. You’ll need to clone the repository and run a module test, such as PostgreSQL.

123Inge commented 3 weeks ago

Sorry for asking so many dumb questions, but I clone the repo, and try to run the PostgreSQL test in the repo, correct? Then I get this error:

Error CS7027 : Error signing output with public key from file '/Users/myname/Documents/testcontainers-dotnet/src/strongname.snk' -- Invalid public key.

Or am I just being a complete potato and misunderstanding everything here?

HofmeisterAn commented 3 weeks ago

The strongname.snk is managed by Git LFS, run (make sure Git LFS is installed):

git lfs pull
123Inge commented 3 weeks ago

@HofmeisterAn I ran git lfs pull and navigated to the /Users/myname/Documents/testcontainers-dotnet/tests/Testcontainers.PostgreSql.Tests and ran dotnet test here. Got the same error as before.

---- System.ArgumentException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:

I also get the same error when trying to run it in Rider.

Made before testing all contexts. See comment below.

123Inge commented 3 weeks ago

WAIT! @HofmeisterAn I forgot to check with the docker contexts. I have two.

~/Documents/someproject $ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT                                     ERROR
default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                         
orbstack    OrbStack                                  unix:///Users/myname/.orbstack/run/docker.sock 

It does not work with default context but does work with the orbstack one. In other word, I get the Testcontainers.PostgreSql.Tests to run, both in terminal and Rider.

Again, dumb question: how do I get this working in my own project? There we use the nuget package.

HofmeisterAn commented 3 weeks ago

If I understand you correctly, it is working with develop. This is very likely a misconfiguration in your environment. Anyway, I just published version 4.0.0 this morning, which includes the enhancements from develop. Please try updating the version in your project to 4.0.0 and test it again 🤞.

123Inge commented 3 weeks ago

Okay, so I updated the testcontainers to version 4.0.0 in my project. Then I ran the tests from Rider and terminal, this was with the orbstack context in docker I got this error again:

System.Net.Http.HttpRequestException: Connection failed

System.Net.Http.HttpRequestException
Connection failed
   at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary`2 headers, IRequestContent data, CancellationToken cancellationToken)
   at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, TimeSpan timeout, CancellationToken token)
   at Docker.DotNet.ContainerOperations.ListContainersAsync(ContainersListParameters parameters, CancellationToken cancellationToken)
   at tests.Utils.DockerUtils.StopContainersAsync(String image) in /Users/myname/Documents/someproject/tests/Utils/DockerUtils.cs:line 36
   at tests.Setup.PostGISContainer.StartAsync(CancellationToken cancellationToken) in /Users/myname/Documents/someproject/tests/Setup/PostGISContainer.cs:line 44
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>g__LogAndRethrow|15_3(<>c__DisplayClass15_0&)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at App.Program.Main(String[] args) in /Users/myname/Documents/someproject/src/App/Program.cs:line 81
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.DeferredHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateHost(IHostBuilder builder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.get_Services()
   at tests.Location.LocationStorageServiceTest..ctor(GridWebApplicationFactory factory) in /Users/myname/Documents/someproject/tests/Location/LocationStorageServiceTest.cs:line 16
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

System.Net.Sockets.SocketException
Can't assign requested address
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket)
   at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP)
   at Docker.DotNet.DockerClient.<>c__DisplayClass6_0.<<-ctor>b__1>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Docker.DotNet.DockerClient.<>c__DisplayClass6_0.<.ctor>b__1(String host, Int32 port, CancellationToken cancellationToken)
   at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary`2 headers, IRequestContent data, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary`2 headers, IRequestContent data, CancellationToken cancellationToken)
   at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, TimeSpan timeout, CancellationToken token)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, TimeSpan timeout, CancellationToken token)
   at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, CancellationToken token)
   at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, CancellationToken token)
   at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, CancellationToken token)
   at Docker.DotNet.ContainerOperations.ListContainersAsync(ContainersListParameters parameters, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Docker.DotNet.ContainerOperations.ListContainersAsync(ContainersListParameters parameters, CancellationToken cancellationToken)
   at tests.Utils.DockerUtils.StopContainersAsync(String image) in /Users/myname/Documents/someproject/tests/Utils/DockerUtils.cs:line 36
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at tests.Utils.DockerUtils.StopContainersAsync(String image)
   at tests.Setup.PostGISContainer.StartAsync(CancellationToken cancellationToken) in /Users/myname/Documents/someproject/tests/Setup/PostGISContainer.cs:line 44
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at tests.Setup.PostGISContainer.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at App.Program.Main(String[] args) in /Users/myname/Documents/someproject/src/App/Program.cs:line 81
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.<CreateHost>b__10_0()
   at System.Threading.Thread.StartCallback()
--- End of stack trace from previous location ---
   at Docker.DotNet.DockerClient.<>c__DisplayClass6_0.<<-ctor>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)

Trying this with the default context in docker I get original error message:

System.ArgumentException: Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly config...

System.ArgumentException
Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/ (Parameter 'DockerEndpointAuthConfig')
   at DotNet.Testcontainers.Guard.ThrowIf[TType](ArgumentInfo`1& argument, Func`2 condition, Func`2 ifClause) in /_/src/Testcontainers/Guard.Null.cs:line 62
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 145
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at tests.Setup.PostGISContainer..ctor(TestSettings testSettings) in /Users/myname/Documents/someproject/tests/Setup/PostGISContainer.cs:line 27
   at InvokeStub_PostGISContainer..ctor(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at App.Program.Main(String[] args) in /Users/myname/Documents/someproject/src/App/Program.cs:line 81
   at InvokeStub_Program.Main(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.DeferredHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateHost(IHostBuilder builder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.get_Services()
   at tests.Location.LocationStorageServiceTest..ctor(GridWebApplicationFactory factory) in /Users/myname/Documents/someproject/tests/Location/LocationStorageServiceTest.cs:line 16
   at InvokeStub_LocationStorageServiceTest..ctor(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

I am going to try and see if my colleague has any idea. Will update this issue again, once I have heard from him. I don't understand what is going, you say this is a misconfiguration in my environment, but this was working last week, and I have done no changes to my environment. I have had this error before with testcontainers not connecting to the docker daemon, but usually just waited a week and then it just worked, but this time it is blocking my work so thats a bummer.

Note: now of course I have made changes to my environment trying to fix this, but since last week, when it was working, and until yesterday at lunch, I did not make any changes to my environment.

HofmeisterAn commented 3 weeks ago

Perhaps I misunderstood, but you didn't encounter any issues running the PostgreSQL module (using the develop branch), right?

The first thing to check is that there are no remaining custom configurations. Ensure that there is no .testcontainers.properties file or any environment variables remaining. Also, double-check Rider and the launch settings for your application.

Next, try running a container from the CLI to see if it starts without issues:

docker run --rm testcontainers/helloworld

Then, try running our resource reaper container:

docker run --rm -v /Users/myname/.orbstack/run/docker.sock:/var/run/docker.sock -p 8080:8080 testcontainers/ryuk

Hopefully, this helps in identifying the issue. Please also share the log messages from Testcontainers.

123Inge commented 2 weeks ago

Sort of a sad update really: Monday morning Orbstack had received an update that solved my problem. Looks like in the changelog that it was an issue with Orbstack? (I don't understand all of it). The sad part here is that I still really don't know what is causing this error. As I said, this has happened before, and prior to this time I did not have much knowledge of docker contexts, docker environment, etc., so changes that has happened there has been out of my control. So if this error comes again, I am not really sure how to solve it, but that will be a problem for the future.

@HofmeisterAn When I was running the Testcontainers.PostgreSql.Tests in the develop branch it ran successfully. No problems. Hope this answer your question. I did not get around to testing the last part you sent there, sorry. My issue is doomed to happen again and then I will test it out!

Thanks for the help from everyone how responded. You guys can probably close this issue if wanted.

HofmeisterAn commented 2 weeks ago

The release notes don't contain anything that seems related to the issues you mentioned, especially since the module test ran successfully. Anyway, let's keep our fingers crossed and hope the issue is resolved and doesn’t occur anymore 🤞 🧙.

geekcharming commented 2 weeks ago

Hi @HofmeisterAn , I am using Testcontainers 4.0.0 and facing a similar issue as above when running with Azure Devops Pipeline. All the tests completely work fine locally but on Azure Devops its not able to find docker. I have read https://dotnet.testcontainers.org/cicd/ and it doesn't suggest of any additional steps.

Error: Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/ (Parameter 'DockerEndpointAuthConfig')

HofmeisterAn commented 2 weeks ago

Do you use a private build agent? If so, you need to install a container runtime (such as Docker) on the agent first.

geekcharming commented 2 weeks ago

No, we're not using a private build agent. We already have containers initialized: Docker daemon API version: '1.44'

HofmeisterAn commented 1 week ago

TC works with Microsoft-hosted agents and GitHub-hosted runners. If you're using the Microsoft-provided agents/runners, no additional configuration is necessary (which vmImage do you use?). I need more information about your environment; otherwise, I won't be able to assist. Could you please create a new issue, share more details about your Docker environment, and try running Ryuk with the following command:

docker run -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 testcontainers/ryuk:0.9.0
geekcharming commented 1 week ago

Thanks @HofmeisterAn, I have created a new issue with more information here: https://github.com/testcontainers/testcontainers-dotnet/issues/1296