Skip to content

Commit 250b7b9

Browse files
committed
Merge pull request #18 from remen/master
Allow using localhost if useNetworkGateway=false
2 parents 0c1c512 + 3a1c7da commit 250b7b9

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

README.md

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

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

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

2930
ComposeExtension(Project project, ComposeUp upTask, ComposeDown downTask) {
3031
this.project = project

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ class ServiceHost {
1010

1111
enum ServiceHostType {
1212
NetworkGateway,
13-
RemoteDockerHost
13+
RemoteDockerHost,
14+
LocalHost
1415
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ 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 {
104+
} else if (extension.useNetworkGateway) {
105105
// read gateway of first containers network
106106
String gateway
107107
Map<String, Object> networkSettings = inspection.NetworkSettings
@@ -115,6 +115,9 @@ class ComposeUp extends DefaultTask {
115115
logger.debug("Will use $gateway as host of $serviceName")
116116
}
117117
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)
118121
}
119122
}
120123

@@ -131,6 +134,7 @@ class ComposeUp extends DefaultTask {
131134
}
132135
else {
133136
switch (host.type) {
137+
case ServiceHostType.LocalHost:
134138
case ServiceHostType.NetworkGateway:
135139
case ServiceHostType.RemoteDockerHost:
136140
if (forwardedPortsInfos.size() > 1) {

0 commit comments

Comments
 (0)