@@ -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 within 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,25 @@ func dockerGatewayIP(profile string) (net.IP, error) {
70
81
if err != nil {
71
82
return nil , errors .Wrapf (err , "get network bridge" )
72
83
}
84
+ networksOutput := strings .TrimSpace (rr .Stdout .String ())
85
+ networksSlice := strings .Fields (networksOutput )
86
+ // Look for the minikube container within each docker network
87
+ for _ , net := range networksSlice {
88
+ // get all containers in the network
89
+ rs , err := runCmd (exec .Command (Docker , "network" , "inspect" , net , "-f" , "{{range $k, $v := .Containers}}{{$v.Name}} {{end}}" ))
90
+ if err != nil {
91
+ return nil , errors .Wrapf (err , "get containers in network" )
92
+ }
93
+ containersSlice := strings .Fields (rs .Stdout .String ())
94
+ if profileInContainers (profile , containersSlice ) {
95
+ bridgeID = net
96
+ break
97
+ }
98
+ }
73
99
74
- bridgeID := strings .TrimSpace (rr .Stdout .String ())
100
+ if bridgeID == "" {
101
+ return nil , errors .Errorf ("unable to determine bridge network id from %q" , networksOutput )
102
+ }
75
103
rr , err = runCmd (exec .Command (Docker , "network" , "inspect" ,
76
104
"--format" , "{{(index .IPAM.Config 0).Gateway}}" , bridgeID ))
77
105
if err != nil {
0 commit comments