File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed
src/main/groovy/com/avast/gradle/dockercompose Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff 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
4847test.doFirst {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments