Closed giammin closed 8 months ago
Hi, could you please verify that the environment variable has not been accidentally set to an empty string (please set it to $env:DOCKER_HOST=$null
)? If TC can resolve the environment variable, it will favor it.
I did some test and I can confirm that $env:DOCKER_HOST is null
Sorry, I cannot reproduce it. The properties file runs fine on my test host.
Your description confuses me. Since you are saying it picks up the property, I would expect that it really cannot connect to the Docker host. Is the port 1234
a typo? Your other two examples use the port 2375
. I do not expect it to be an issue in Testcontainers.
the 1234
port was an error in a copy paste. My .testcontainers.properties
file has the correct value:
docker.host=tcp://localhost:2375
how can i test what value is used in code?
could it be a MsSqlBuilder
bug?
another thought: my .testcontainers.properties
has only the docker.host line, do I need to set other variables?
Testcontainers tries to resolve various Docker host configurations. It will select the first one it can establish a connection with. These are the configurations we check:
According to the error message, none of the providers is able to establish a connection to Docker. Debug into the following class to debug the environment or properties file configuration (it would be interesting which _dockerEngine
it chooses):
This part attempts to access (ping) the Docker host (if it succeeds, it will pick the endpoint and run the tests against it):
another thought: my
.testcontainers.properties
has only the docker.host line, do I need to set other variables?
No, that is not necessary. For example, Testcontainers Cloud does exactly the same to configure a Docker remote host.
I finally discovered what was the problem:
# comments in the .testcontainers.properties
I copy/pasted the example file from here: https://java.testcontainers.org/features/configuration/
and modified it so my docker.host file line was:
docker.host=tcp://my.docker.host:1234 # Equivalent to the DOCKER_HOST environment variable.
I deleted the comment and now it works as expected
I deleted the comment and now it works as expected
😬
TBH, I am not sure if this is valid. Wikipedia says:
Comment lines in .properties files are denoted by the number sign (#) or the exclamation mark (!) as the first non blank character
But, of course, we can only select the value until the first #
or !
occurs.
maybe the host value is not trimmed?
Whitespaces are not a problem, but a non-blank characters following the host address are. The current implementation takes the value as it is. Given that .NET lacks native support for .properties
files, we prioritize only the essential features.
ok, so the error in my .testcontainers.properties
was that the comment was not at the beginning of the line.
modifing the last line with this would prevent my error:
.ToDictionary(
property => property[0],
property => property[1].Trim().Split(new[] { ' ','#' },2, StringSplitOptions.RemoveEmptyEntries)[0]);
modifing the last line with this would prevent my error:
I had something similar in mind :+1:, but we need to take care of (consider) the escape sequences too.
I will close this issue in favor of #1041 (to keep the conversation clean). Thanks for bringing this up.
thanks for your support and for this awesome library
Testcontainers version
3.5.0
Using the latest Testcontainers version?
Yes
Host OS
windows
Host arch
x64
.NET version
7.0.403
Docker version
Docker info
What happened?
I'm running testcontainers from a windows pc using the docker engine running on wsl2 (no docker desktop, custom docker installation directly on wsl2 debian)
It works fine if I set from code
WithDockerEndpoint
it work if i set environment var
DOCKER_HOST
but if i set
docker.host
in~/.testcontainers.properties
I get the error:
I know if it is reading that
docker.host
value because if I assign non valid url value it gives me an url exception:Relevant log output
No response
Additional information
No response