Skip to content

Commit f7148c2

Browse files
committed
Look for .dockercfg in user.home instead of DOCKER_CONFIG
1 parent e80848b commit f7148c2

4 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public String getDockerConfigPath() {
238238
public DockerConfigFile getDockerConfig() {
239239
if (dockerConfig == null) {
240240
try {
241-
dockerConfig = DockerConfigFile.loadConfig(new File(getDockerConfigPath()));
241+
dockerConfig = DockerConfigFile.loadConfig(new File(System.getProperty("user.home")), new File(getDockerConfigPath()));
242242
} catch (IOException e) {
243243
throw new DockerClientException("Failed to parse docker configuration file", e);
244244
}

src/main/java/com/github/dockerjava/core/DockerConfigFile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ public String toString() {
112112
return "DockerConfigFile [auths=" + auths + "]";
113113
}
114114

115-
public static DockerConfigFile loadConfig(File dockerConfigPath) throws IOException {
115+
public static DockerConfigFile loadConfig(File userHome, File dockerConfigPath) throws IOException {
116116
//parse new docker config file format
117117
DockerConfigFile dockerConfig = loadCurrentConfig(dockerConfigPath);
118118

119119
//parse old auth config file format
120120
if (dockerConfig == null) {
121-
dockerConfig = loadLegacyConfig(dockerConfigPath);
121+
dockerConfig = loadLegacyConfig(userHome);
122122
}
123123

124124
//otherwise create default config
@@ -150,8 +150,8 @@ private static DockerConfigFile loadCurrentConfig(File dockerConfigPath) throws
150150
}
151151
}
152152

153-
private static DockerConfigFile loadLegacyConfig(File dockerConfigPath) throws IOException {
154-
File dockerLegacyCfgFile = new File(dockerConfigPath, File.separator + DOCKER_LEGACY_CFG);
153+
private static DockerConfigFile loadLegacyConfig(File userHome) throws IOException {
154+
File dockerLegacyCfgFile = new File(userHome, DOCKER_LEGACY_CFG);
155155

156156
if (!dockerLegacyCfgFile.exists() || !dockerLegacyCfgFile.isFile()) {
157157
return null;

src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public void withDockerTlsVerify() throws Exception {
208208
@Test
209209
public void testGetAuthConfigurationsFromDockerCfg() throws URISyntaxException {
210210
File cfgFile = new File(Resources.getResource("com.github.dockerjava.core/registry.v1").toURI());
211+
System.setProperty("user.home", cfgFile.getAbsolutePath());
211212
DefaultDockerClientConfig clientConfig = new DefaultDockerClientConfig(URI.create(
212213
"unix://foo"), cfgFile.getAbsolutePath(), "apiVersion", "registryUrl", "registryUsername", "registryPassword",
213214
"registryEmail", null);

src/test/java/com/github/dockerjava/core/DockerConfigFileTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void nonExistent() throws IOException {
156156
}
157157

158158
private DockerConfigFile runTest(String testFileName) throws IOException {
159-
return DockerConfigFile.loadConfig(new File(FILESROOT, testFileName));
159+
return DockerConfigFile.loadConfig(new File(FILESROOT, testFileName), new File(FILESROOT, testFileName));
160160
}
161161

162162
}

0 commit comments

Comments
 (0)