Skip to content

Conversation

@usmanovbf
Copy link

It is based on #1770

Copy link
Member

@bsideup bsideup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is EnvironmentAndSystemPropertyClientProviderStrategy that should use the environment variables, doesn't it work for you?

@usmanovbf
Copy link
Author

@bsideup Unfortunately not. Because first valid strategy choosed as the UnixSocketClientProviderStrategy not the EnvironmentAndSystemPropertyClientProviderStrategy. I don't know why so that changed UnixSocketClientProviderStrategy

@rnorth rnorth added this to the next milestone Sep 8, 2019
@bsideup bsideup modified the milestones: 1.12.3, next Oct 26, 2019
@rnorth rnorth removed this from the next milestone Oct 30, 2019
@rnorth rnorth self-assigned this Nov 1, 2019
@rnorth
Copy link
Member

rnorth commented Dec 7, 2019

OK, I've finally had time to look into why the EnvironmentAndSystemPropertyClientProviderStrategy wasn't taking effect - @usmanovbf is quite correct that it doesn't. We have:

https://github.com/testcontainers/testcontainers-java/blob/master/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java#L25-L27

So, if DOCKER_HOST points to a unix socket and the system is not Linux, the EnvironmentAndSystemPropertyClientProviderStrategy will not be used and this problem will happen. We've probably been lucky that virtually all environments where DOCKER_HOST matters (e.g. CI) are Linux based.

Given that we have better code in UnixSocketClientProviderStrategy for checking the socket availability, I'm happier to let this class be environment variable aware and rely less on EnvironmentAndSystemPropertyClientProviderStrategy.

However, I'd like to make a couple of tweaks to this PR to improve the other strategies along similar lines. I'll do that myself and push shortly.

@rnorth
Copy link
Member

rnorth commented Dec 7, 2019

/AzurePipelines run Windows 10 - Docker for Windows

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rnorth
Copy link
Member

rnorth commented Dec 23, 2019

@bsideup we discussed this very briefly in person last week, and I think you spotted a flaw. Do you remember what it was? 😬

@bsideup
Copy link
Member

bsideup commented Dec 23, 2019

@rnorth yes. Strategies (like the npipe one) must filter the value of the env variable to prevent wrong selection (e.g. npipe strategy talking over TCP)

@rnorth rnorth requested a review from bsideup December 26, 2019 13:05
@Alex-ala
Copy link

Is there also a way to apply the hosts DOCKER_HOST to Ryuk, if its a unix socket? (

binds.add(new Bind("//var/run/docker.sock", new Volume("/var/run/docker.sock")));
)
That would resolve issues with deployents that have the docker.sock in an unusual place.

@rnorth rnorth dismissed bsideup’s stale review January 24, 2020 20:16

I've updated the PR since

@rnorth
Copy link
Member

rnorth commented Jan 24, 2020

/AzurePipelines run Windows 10 - Docker for Windows

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rnorth
Copy link
Member

rnorth commented Feb 5, 2020

Just for sanity's sake, I've tested this in our CI environment which is DinD with DOCKET_HOST set to a tcp address (which is fairly exotic). There were no surprises, and it seems to continue to just work here too.

[build:L1390:239s] org.testcontainers.images.ImagePullPolicyTest STANDARD_OUT
[build:L1391:239s]     09:39:10.531 DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
[build:L1392:240s]     09:39:11.043 INFO  org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy - Found docker client settings from environment
[build:L1393:240s]     09:39:11.046 INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with Environment variables, system properties and defaults. Resolved dockerHost=tcp://172.18.0.1:2375
[build:L1394:240s]     09:39:11.047 DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Checking Docker OS type for Environment variables, system properties and defaults. Resolved dockerHost=tcp://172.18.0.1:2375
[build:L1395:240s]     09:39:11.364 INFO  org.testcontainers.DockerClientFactory - Docker host IP address is 172.18.0.1
[build:L1396:240s]     09:39:11.418 INFO  org.testcontainers.DockerClientFactory - Connected to docker:
[build:L1397:240s]       Server Version: 19.03.0
[build:L1398:240s]       API Version: 1.40
[build:L1399:240s]       Operating System: Alpine Linux v3.10 (containerized)
[build:L1400:240s]       Total Memory: 7963 MB

Given that this is tested on a variety of CI and local environments, I think I'm happy that this doesn't introduce any regressions. WDYT @bsideup, @kiview?

@rnorth rnorth self-assigned this Jul 9, 2020
@rnorth rnorth changed the title Obtain DOCKER_HOST from env (#1770) WIP: Obtain DOCKER_HOST from env (#1770) Jul 10, 2020
@rnorth rnorth changed the title WIP: Obtain DOCKER_HOST from env (#1770) Obtain DOCKER_HOST from env (#1770) Jul 10, 2020
@rnorth rnorth changed the title Obtain DOCKER_HOST from env (#1770) Always obtain DOCKER_HOST from env (#1770) Jul 10, 2020
@bsideup bsideup added this to the next milestone Jul 11, 2020
Copy link
Member

@bsideup bsideup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current master's state removes the "TCP or Linux" condition on EnvironmentAndSystemPropertyClientProviderStrategy and now it should take precedence over UnixSocketClientProviderStrategy, which means that we don't need to read DOCKER_HOST there :D So I'd revert it.

But the getDockerUnixSocketPath() change is still helpful.


protected static final String DOCKER_SOCK_PATH = "//./pipe/docker_engine";
private static final String SOCKET_LOCATION = "npipe://" + DOCKER_SOCK_PATH;
private static final String SOCKET_LOCATION = System.getenv().getOrDefault("DOCKER_HOST", "npipe://" + DOCKER_SOCK_PATH);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is unnecessary now

Comment on lines +17 to 18
protected static final String SOCKET_LOCATION = "unix:///var/run/docker.sock";
protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (reducing the changeset):

Suggested change
protected static final String SOCKET_LOCATION = "unix:///var/run/docker.sock";
protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";
protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";
private static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH;

@Override
protected boolean isApplicable() {
return SystemUtils.IS_OS_LINUX;
return SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC_OSX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

@Override
protected boolean isApplicable() {
return SystemUtils.IS_OS_LINUX;
return SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC_OSX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brave new world:

Suggested change
return SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC_OSX;
return SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC;

Co-authored-by: Sergei Egorov <bsideup@gmail.com>
@rnorth
Copy link
Member

rnorth commented Jul 12, 2020

We'll tackle this in #2985 instead, as the changes there make the majority of this PR moot.

@rnorth rnorth closed this Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants