@@ -58,9 +58,20 @@ func digDNS(ociBin, containerName, dns string) (net.IP, error) {
58
58
return ip , nil
59
59
}
60
60
61
+ // profileInContainers checks whether the profile is withing the containers list
62
+ func profileInContainers (profile string , containers []string ) bool {
63
+ for _ , container := range containers {
64
+ if container == profile {
65
+ return true
66
+ }
67
+ }
68
+ return false
69
+ }
70
+
61
71
// dockerGatewayIP gets the default gateway ip for the docker bridge on the user's host machine
62
72
// gets the ip from user's host docker
63
73
func dockerGatewayIP (profile string ) (net.IP , error ) {
74
+ var bridgeID string
64
75
// check if using custom network first
65
76
if networkExists (profile ) {
66
77
ip := net .ParseIP (DefaultGateway )
@@ -70,8 +81,28 @@ func dockerGatewayIP(profile string) (net.IP, error) {
70
81
if err != nil {
71
82
return nil , errors .Wrapf (err , "get network bridge" )
72
83
}
73
-
74
- bridgeID := strings .TrimSpace (rr .Stdout .String ())
84
+ networksOutput := strings .TrimSpace (rr .Stdout .String ())
85
+ networksSlice := strings .Fields (networksOutput )
86
+ if len (networksSlice ) == 1 {
87
+ bridgeID = networksOutput
88
+ } else {
89
+ // Look for the minikube container within each docker network
90
+ for _ , net := range networksSlice {
91
+ // get all containers in the network
92
+ rs , err := runCmd (exec .Command (Docker , "network" , "inspect" , net , "-f" , "'{{range $k, $v := .Containers}}{{$v.Name}} {{end}}'" ))
93
+ if err != nil {
94
+ return nil , errors .Wrapf (err , "get containers in network" )
95
+ }
96
+ containersSlice := strings .Fields (rs .Stdout .String ())
97
+ if profileInContainers (profile , containersSlice ) {
98
+ bridgeID = net
99
+ break
100
+ }
101
+ }
102
+ }
103
+ if bridgeID == "" {
104
+ return nil , errors .Errorf ("Error finding docker network" )
105
+ }
75
106
rr , err = runCmd (exec .Command (Docker , "network" , "inspect" ,
76
107
"--format" , "{{(index .IPAM.Config 0).Gateway}}" , bridgeID ))
77
108
if err != nil {
0 commit comments