Explorar o código

feat: handle multiple proxy networks

Nicolas Duchon %!s(int64=2) %!d(string=hai) anos
pai
achega
b88d33d2f3
Modificáronse 2 ficheiros con 14 adicións e 4 borrados
  1. 10 3
      nginx.tmpl
  2. 4 1
      test/test_host-network-mode/test_host-network-mode.yml

+ 10 - 3
nginx.tmpl

@@ -68,9 +68,16 @@
             {{- continue }}
         {{- end }}
         {{- if eq .Name "host" }}
-    #         {{ .Name }} (host network; using {{ (index $.globals.CurrentContainer.Networks 0).Name }} gateway)
-            {{- $ip = (index $.globals.CurrentContainer.Networks 0).Gateway }}
-            {{- continue }}
+            {{- range sortObjectsByKeysAsc $.globals.CurrentContainer.Networks "Name" }}
+                {{- if and . .Gateway }}
+    #         container is in host network mode, using {{ .Name }} gateway IP
+                    {{- $ip = .Gateway }}
+                    {{- break }}
+                {{- end }}
+            {{- end }}
+            {{- if $ip }}
+                {{- continue }}
+            {{- end }}
         {{- end }}
         {{- if and (not (index $.globals.networks .Name)) (not $.globals.networks.host) }}
     #         {{ .Name }} (unreachable)

+ 4 - 1
test/test_host-network-mode/test_host-network-mode.yml

@@ -2,6 +2,8 @@ version: "2"
 
 networks:
   net1:
+    internal: true
+  net2:
 
 services:
   bridge-network:
@@ -10,7 +12,7 @@ services:
       WEB_PORTS: "80"
       VIRTUAL_HOST: "bridge-network.nginx-proxy.tld"
     networks:
-      - net1
+      - net2
 
   host-network:
     image: web
@@ -26,3 +28,4 @@ services:
       - /var/run/docker.sock:/tmp/docker.sock:ro
     networks:
       - net1
+      - net2