File tree Expand file tree Collapse file tree 4 files changed +9
-2
lines changed
src/main/groovy/com/avast/gradle/dockercompose Expand file tree Collapse file tree 4 files changed +9
-2
lines changed Original file line number Diff line number Diff 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
4748test.doFirst {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -10,5 +10,6 @@ class ServiceHost {
1010
1111enum ServiceHostType {
1212 NetworkGateway ,
13- RemoteDockerHost
13+ RemoteDockerHost ,
14+ LocalHost
1415}
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments