question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't connect to Docker running in WSL2 VM if Testcontainers runs on Windows and Docker Desktop is not used

See original GitHub issue

Test container failed to start and throws Exception when try to run test case.

Host system: Windows 10 WSL2 based system: Ubuntu App for windows Docker installed inside: Ubuntu App for windows

Using WSL2 based Ubuntu App on windows and setup docker in it. We are able to connect containers run inside it from host system i.e. Windows 10 through Ubuntu App IP address and port on which containers are running. In case of test containers it fails and throws below exception

Exception:

java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

	at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$7(DockerClientProviderStrategy.java:215)
	at java.util.Optional.orElseThrow(Optional.java:290)
	at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:207)
	at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:136)
	at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:178)
	at org.testcontainers.LazyDockerClient.getDockerClient(LazyDockerClient.java:14)
	at org.testcontainers.LazyDockerClient.authConfig(LazyDockerClient.java:12)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:310)
	at infrastructure.DatabaseContainer.start(DatabaseContainer.java:30)
	at com.ecw.hplus.chat.ChannelFeatureShould.before(ChannelFeatureShould.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Test case file:

import infrastructure.DatabaseContainer;
import infrastructure.MySqlDatabaseContainer;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class AFeatureShould extends SimpleRepositoryTest {

    private static final MySqlDatabaseContainer mysql = new MySqlDatabaseContainer("mysql.sql");
    
    @Parameterized.Parameters
    public static DatabaseContainer[] getDatabaseContainer() {
        return new DatabaseContainer[]{
                mysql
        };
    }

    @BeforeClass
    public static void before() {
        mysql.start();
    }

    @Test
    public void test() {
        // assertions
    }
}

Tried to mitigate this issue by modifying /etc/docker/deamon.json and C:/Users/myuser/.testcontainers.properties files and not succeeded.

/etc/docker/deamon.json:

{
        "hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]
}

C:/Users/myuser/.testcontainers.properties:

docker.client.strategy=org.testcontainers.dockerclient.NpipeSocketClientProviderStrategy
docker.host=tcp\://<ip-of-ubuntu-app>\:2375

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
sz763commented, Feb 12, 2022

I had faced with same issue. The following steps fixed it https://gist.github.com/sz763/3b0a5909a03bf2c9c5a057d032bd98b7, I hope it will help you. UPD: saurabh4studies pay attention, you’ve incorrect file name deamon.json , it must be daemon.json.

0reactions
eddumelendezcommented, Nov 30, 2022

Closing due to it is resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WSL2 Cannot connect to the Docker daemon - Stack Overflow
1.open windows docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS · 2.and then Go to Settings -- ...
Read more >
"Cannot connect to the Docker daemon at tcp://localhost:2375 ...
I'm trying to execute Docker commands from a WSL bash terminal and am getting the following error… $ docker ps Cannot connect to...
Read more >
Install Docker on Windows (WSL) without Docker Desktop
Add user to docker group​​ Two ways to obtain this access: Run docker as root (i.e. sudo docker ) Through group membership, grant...
Read more >
Run the Azure Cosmos DB Emulator on Docker for Linux
Learn how to run and use the Azure Cosmos DB Linux Emulator on Linux, and macOS. Using the emulator you can develop and...
Read more >
How to access service running on host from WSL2 ...
Connect to any Windows server using the copied IP address. ... if you also use Docker Desktop, you can access your Windows host...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found