ARTICLE AD BOX
I am following a Spring Boot 3 course and trying to run integration tests using Testcontainers with PostgreSQL. My environment is Windows 11, running Docker Desktop, but the tests fail immediately with connection errors.
Environment:
OS: Windows 11
Java: 21 (Corretto)
Spring Boot: 3.4.1
Testcontainers: 1.20.4
Docker Desktop: Running (v4.37+)
The Problem: When running PersonControllerTest, I get java.lang.IllegalStateException: Could not find a valid Docker environment. The logs show that both EnvironmentAndSystemPropertyClientProviderStrategy and NpipeSocketClientProviderStrategy failed.
What I have tried so far:
Docker Config: Enabled "Expose daemon on tcp://localhost:2375 without TLS" in Docker Desktop settings.
Environment Variables: Added DOCKER_HOST with value tcp://localhost:2375 to both User and System environment variables in Windows.
Verification: Ran netstat -an | findstr 2375 and confirmed the port is listening (TCP 0.0.0.0:2375 ... LISTENING).
Restart: Restarted IntelliJ IDEA and the PC multiple times.
Config File: Tried creating a .testcontainers.properties file in user home with docker.host=tcp://localhost:2375, but it didn't work.
Code Snippet (AbstractIntegrationTest.java):
Java
@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class) public class AbstractIntegrationTest { static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { // Changed from postgres:18 to postgres:16-alpine just to be safe static PostgreSQLContainer<?> postgresSQL = new PostgreSQLContainer<>("postgres:16-alpine"); private static void startContainers() { Startables.deepStart(Stream.of(postgresSQL)).join(); } @Override public void initialize(ConfigurableApplicationContext applicationContext) { startContainers(); // ... (property mapping logic) } } }Relevant Error Log:
Plaintext
java.lang.IllegalStateException: Could not find a valid Docker environment. Please check configuration. Attempted configurations were: EnvironmentAndSystemPropertyClientProviderStrategy: failed with exception BadRequestException (Status 400: ...) NpipeSocketClientProviderStrategy: failed with exception BadRequestException (Status 400: ...)The subsequent error is ApplicationContext failure threshold (1) exceeded, which implies the context failed to start initially due to the Docker issue.
Does anyone know why Testcontainers cannot connect to Docker Desktop on Windows even with DOCKER_HOST set explicitly?
