diff --git a/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java b/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java index 8517d89a9..1ccee82c1 100644 --- a/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java +++ b/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java @@ -238,7 +238,7 @@ public String getDockerConfigPath() { public DockerConfigFile getDockerConfig() { if (dockerConfig == null) { try { - dockerConfig = DockerConfigFile.loadConfig(new File(getDockerConfigPath())); + dockerConfig = DockerConfigFile.loadConfig(new File(System.getProperty("user.home")), new File(getDockerConfigPath())); } catch (IOException e) { throw new DockerClientException("Failed to parse docker configuration file", e); } diff --git a/src/main/java/com/github/dockerjava/core/DockerConfigFile.java b/src/main/java/com/github/dockerjava/core/DockerConfigFile.java index 01cacb5c8..24e7a70c7 100644 --- a/src/main/java/com/github/dockerjava/core/DockerConfigFile.java +++ b/src/main/java/com/github/dockerjava/core/DockerConfigFile.java @@ -112,13 +112,13 @@ public String toString() { return "DockerConfigFile [auths=" + auths + "]"; } - public static DockerConfigFile loadConfig(File dockerConfigPath) throws IOException { + public static DockerConfigFile loadConfig(File userHome, File dockerConfigPath) throws IOException { //parse new docker config file format DockerConfigFile dockerConfig = loadCurrentConfig(dockerConfigPath); //parse old auth config file format if (dockerConfig == null) { - dockerConfig = loadLegacyConfig(dockerConfigPath); + dockerConfig = loadLegacyConfig(userHome); } //otherwise create default config @@ -150,8 +150,8 @@ private static DockerConfigFile loadCurrentConfig(File dockerConfigPath) throws } } - private static DockerConfigFile loadLegacyConfig(File dockerConfigPath) throws IOException { - File dockerLegacyCfgFile = new File(dockerConfigPath, File.separator + DOCKER_LEGACY_CFG); + private static DockerConfigFile loadLegacyConfig(File userHome) throws IOException { + File dockerLegacyCfgFile = new File(userHome, DOCKER_LEGACY_CFG); if (!dockerLegacyCfgFile.exists() || !dockerLegacyCfgFile.isFile()) { return null; diff --git a/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java b/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java index 037a82690..6e7770186 100644 --- a/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java +++ b/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java @@ -208,6 +208,7 @@ public void withDockerTlsVerify() throws Exception { @Test public void testGetAuthConfigurationsFromDockerCfg() throws URISyntaxException { File cfgFile = new File(Resources.getResource("com.github.dockerjava.core/registry.v1").toURI()); + System.setProperty("user.home", cfgFile.getAbsolutePath()); DefaultDockerClientConfig clientConfig = new DefaultDockerClientConfig(URI.create( "unix://foo"), cfgFile.getAbsolutePath(), "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail", null); diff --git a/src/test/java/com/github/dockerjava/core/DockerConfigFileTest.java b/src/test/java/com/github/dockerjava/core/DockerConfigFileTest.java index 7f121c69a..9dc52674d 100644 --- a/src/test/java/com/github/dockerjava/core/DockerConfigFileTest.java +++ b/src/test/java/com/github/dockerjava/core/DockerConfigFileTest.java @@ -156,7 +156,7 @@ public void nonExistent() throws IOException { } private DockerConfigFile runTest(String testFileName) throws IOException { - return DockerConfigFile.loadConfig(new File(FILESROOT, testFileName)); + return DockerConfigFile.loadConfig(new File(FILESROOT, testFileName), new File(FILESROOT, testFileName)); } }