Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testcontainers: DOCKER_HOST is not listening error when running Spring integration tests

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?

like image 255
jessiepinkman Avatar asked Sep 06 '25 03:09

jessiepinkman


1 Answers

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.

like image 116
Jérôme Guidon Avatar answered Sep 08 '25 20:09

Jérôme Guidon