"Could not find a valid Docker environment" error while running tests from Jenkins on the Ubuntu

See original GitHub issue

The environment:

  • Host machine: Ubuntu 16.04 with Docker installed and running;
  • Jenkins which is run via Docker container on the same host machine.

I am using testcontainers-java in my project and trying to setup executing SeleniumWebdriver tests via Maven from the Jenkins CI. Example code is taken from the official documentation and works perfectly if I run tests from IDE installed on the same Linux host machine, or if I run tests from a terminal via Maven - testcontainers-java starts an appropriate container and I receive correct data from the browser under test.

However, when I try to run the same tests with the same set of Maven commands from a Jenkins job - I receive the following error:

java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$2(DockerClientProviderStrategy.java:146) at java.util.Optional.orElseThrow(Optional.java:290) at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:138) at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:99) at org.testcontainers.containers.GenericContainer.<init>(GenericContainer.java:126) at org.testcontainers.containers.GenericContainer.<init>(GenericContainer.java:166) at org.testcontainers.containers.BrowserWebDriverContainer.<init>(BrowserWebDriverContainer.java:61)

I suspect that there is maybe some issue because Jenkins itself is running inside another container and cannot get access to the installed Docker instance from inside. Is there any way to solve this issue? I was trying to search for a solution a lot but didn’t succeed. This forum is my last hope

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

17reactions
endless-qacommented, Mar 23, 2018

So, the final solution that works for me:

  1. Add jenkins user to the docker group: sudo usermod -aG docker jenkins
  2. Reboot a host machine. Optionally, you can open the terminal under the jenkins user and run the groups command to make sure that there is the docker group in the list.

After that Jenkins is able to deal with the docker.sock file and TestContainers can see the Docker installation.

12reactions
jabrenacommented, Nov 6, 2018

In my case, I solved the issue in the following way:

  • sudo chmod 666 /var/run/docker.sock
Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Container test cases are failing due to "Could not find a ...
In my case this error caused by root permission. If you are using ubuntu, docker wants permission to create container and testcontainers can ......
Read more >
Could not find a valid Docker environment issue
Hi All, I have installed and setup IntelliJ on a new laptop (Mac M1). Currently the integration tests failed because can't run docker......
Read more >
Spring – Test Container test cases are failing due to “Could not find ...
In my case this error caused by root permission. If you are using ubuntu, docker wants permission to create container and testcontainers can...
Read more >
Jenkins User Handbook
This chapter will lead you through installing an instance of Jenkins on a system for learning purposes and understanding basic Jenkins concepts.
Read more >
PKIX path building failed error message
SunCertPathBuilderException: unable to find valid certification path to ... Elasticsearch task that is running in a docker fails with the following error:.
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