I am trying to run Spring integration tests with Testcontainers, but I keep getting the following error:
WARN org.testcontainers.dockerclient.DockerClientProviderStrategy -- DOCKER_HOST unix:///var/run/docker.sock is not listening
I have checked that the Docker daemon is running and that the Docker socket is accessible at /var/run/docker.sock. I have also added my user to the docker group and restarted my system, but I am still getting the same error.
Here is the relevant code from my test class:
@SpringBootTest
@AutoConfigureMockMvc
class ProductServiceApplicationTests {
@Container
static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:4.4.2");
@DynamicPropertySource
static void setProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.mongodb.uri", mongoDBContainer::getReplicaSetUrl);
}
// ...
}
What could be causing this error, and how can I fix it?
It seems like the user running the java process or the group that he belongs to misses access to /var/run/docker.sock
.
The user needs at least read and write permission to /var/run/docker.sock
.
To make sure you can get enought access to run your test, you can try the most permissive way: chmod 777 /var/run/docker.sock
.
If for security policy reasons you cannot allow everyone access to docker.sock, please check the permission and ownership of docker.sock with ls -la /var/run/docker.sock
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With