Skip to content

Commit c870300

Browse files
committed
Merge pull request #20 from remen/master
Add logic for Docker for Mac and remove useNetworkGateway
2 parents 250b7b9 + cfd3d90 commit c870300

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ dockerCompose {
4242
// removeContainers = false
4343
// removeImages = true
4444
// removeVolumes = false
45-
// useNetworkGateway = false // Connect to localhost instead of gateway. Useful for Docker for Mac.
4645
}
4746
4847
test.doFirst {

src/main/groovy/com/avast/gradle/dockercompose/ComposeExtension.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ComposeExtension {
2525
boolean removeContainers = true
2626
boolean removeImages = false
2727
boolean removeVolumes = true
28-
boolean useNetworkGateway = true
2928

3029
ComposeExtension(Project project, ComposeUp upTask, ComposeDown downTask) {
3130
this.project = project

src/main/groovy/com/avast/gradle/dockercompose/tasks/ComposeUp.groovy

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ class ComposeUp extends DefaultTask {
101101
if (dockerHost) {
102102
logger.debug("'DOCKER_HOST environment variable detected - will be used as hostname of service $serviceName'")
103103
new ServiceHost(host: dockerHost.toURI().host, type: ServiceHostType.RemoteDockerHost)
104-
} else if (extension.useNetworkGateway) {
104+
} else if (isMac()) {
105+
// If running on Mac OS and DOCKER_HOST is not set, we can assume that
106+
// we are using Docker for Mac, in which case we should connect to localhost
107+
logger.debug("Will use localhost as host of $serviceName")
108+
new ServiceHost(host: 'localhost', type: ServiceHostType.LocalHost)
109+
} else {
105110
// read gateway of first containers network
106111
String gateway
107112
Map<String, Object> networkSettings = inspection.NetworkSettings
@@ -115,9 +120,6 @@ class ComposeUp extends DefaultTask {
115120
logger.debug("Will use $gateway as host of $serviceName")
116121
}
117122
new ServiceHost(host: gateway, type: ServiceHostType.NetworkGateway)
118-
} else {
119-
logger.debug("Will use localhost as host of $serviceName")
120-
new ServiceHost(host: 'localhost', type: ServiceHostType.LocalHost)
121123
}
122124
}
123125

@@ -188,4 +190,8 @@ class ComposeUp extends DefaultTask {
188190
os.toString().trim()
189191
}
190192
}
193+
194+
private static boolean isMac() {
195+
System.getProperty("os.name").toLowerCase().startsWith("mac")
196+
}
191197
}

0 commit comments

Comments
 (0)