testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

[Bug]: Could not find a valid Docker environment - Docker Desktop for Linux

Open wanderdev0 opened this issue 3 years ago • 3 comments

Module

Core

Testcontainers version

1.18.0

Using the latest Testcontainers version?

Yes

Host OS

Linux (Ubuntu 22.04)

Host Arch

x86_64

Docker version

lient: Docker Engine - Community
 Cloud integration: v1.0.31
 Version:           23.0.2
 API version:       1.41 (downgraded from 1.42)
 Go version:        go1.19.7
 Git commit:        569dd73
 Built:             Mon Mar 27 16:16:30 2023
 OS/Arch:           linux/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.17.0 (99724)
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:32:04 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

I was trying to run a project created by primarily Mac users, set up to use testcontainers 1.17.2 on my Ubuntu 22.04 using Docker Desktop for Linux and when running the testcontainer-based tests got multiple errors stating Could not find a valid Docker environment. Please see logs and check configuration.

After some googling I came upon #6045, and adapting the suggested approach for Mac for Linux Docker Desktop I found a work-around of running

sudo ln -s $HOME/.docker/desktop/docker.sock /var/run/docker.sock

Which fixes the issue. See also: my comment on the Mac bug.

I later upgraded our project to 1.18.0 and removed the symbolic link to see if this would result in the same issue, and it turns out that it does, where the above is still a workaround for it on this most recent version too.

At this point in time I think it might make sense to provide this solution in the offical docs (as it is provided for Mac). Or a different approach if a better solution might exist for Docker Desktop for Linux.

Relevant log output

java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
       org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$7(DockerClientProviderStrategy.java:256)
       java.base/java.util.Optional.orElseThrow(Optional.java:403)
       org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:247)
       org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:150)
       org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:186)
       org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:104)
       com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
       org.testcontainers.containers.GenericContainer.start(GenericContainer.java:321)
       ...
       org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$12(ClassBasedTestDescriptor.java:395)
       [...]

Additional Information

https://github.com/testcontainers/testcontainers-java/discussions/6045

wanderdev0 avatar Apr 06 '23 21:04 wanderdev0

@eddumelendez I created this PR that adds a comment to the same table that was mentioned in bug report #6045 for Mac (https://www.testcontainers.org/supported_docker_environment/) as it seems to be an equivalent workaround for Docker Desktop for Linux.

Please do feel free to let me know if a better solution exists!

wanderdev0 avatar Apr 06 '23 21:04 wanderdev0

Closing as duplicated. See https://github.com/testcontainers/testcontainers-java/issues/6426

eddumelendez avatar Apr 07 '23 06:04 eddumelendez

Hey, I was struggling with it for a while, then that solution worked for me Thanks :laughing:

phenriquecarmo avatar Jan 22 '24 01:01 phenriquecarmo