mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 09:48:14 +00:00
feat: support proxy + container in host network mode
This commit is contained in:
parent
b88d33d2f3
commit
35b1493e16
@ -68,6 +68,12 @@
|
|||||||
{{- continue }}
|
{{- continue }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if eq .Name "host" }}
|
{{- if eq .Name "host" }}
|
||||||
|
{{- /* Handle containers in host nework mode */}}
|
||||||
|
{{- if (index $.globals.networks "host") }}
|
||||||
|
# both container and proxy are in host network mode, using localhost IP
|
||||||
|
{{- $ip = "127.0.0.1" }}
|
||||||
|
{{- continue }}
|
||||||
|
{{- end }}
|
||||||
{{- range sortObjectsByKeysAsc $.globals.CurrentContainer.Networks "Name" }}
|
{{- range sortObjectsByKeysAsc $.globals.CurrentContainer.Networks "Name" }}
|
||||||
{{- if and . .Gateway }}
|
{{- if and . .Gateway }}
|
||||||
# container is in host network mode, using {{ .Name }} gateway IP
|
# container is in host network mode, using {{ .Name }} gateway IP
|
||||||
|
@ -161,6 +161,10 @@ def container_ip(container: Container):
|
|||||||
if "bridge" in net_info:
|
if "bridge" in net_info:
|
||||||
return net_info["bridge"]["IPAddress"]
|
return net_info["bridge"]["IPAddress"]
|
||||||
|
|
||||||
|
# container is running in host network mode
|
||||||
|
if "host" in net_info:
|
||||||
|
return "127.0.0.1"
|
||||||
|
|
||||||
# not default bridge network, fallback on first network defined
|
# not default bridge network, fallback on first network defined
|
||||||
network_name = list(net_info.keys())[0]
|
network_name = list(net_info.keys())[0]
|
||||||
return net_info[network_name]["IPAddress"]
|
return net_info[network_name]["IPAddress"]
|
||||||
@ -174,6 +178,10 @@ def container_ipv6(container):
|
|||||||
if "bridge" in net_info:
|
if "bridge" in net_info:
|
||||||
return net_info["bridge"]["GlobalIPv6Address"]
|
return net_info["bridge"]["GlobalIPv6Address"]
|
||||||
|
|
||||||
|
# container is running in host network mode
|
||||||
|
if "host" in net_info:
|
||||||
|
return "::1"
|
||||||
|
|
||||||
# not default bridge network, fallback on first network defined
|
# not default bridge network, fallback on first network defined
|
||||||
network_name = list(net_info.keys())[0]
|
network_name = list(net_info.keys())[0]
|
||||||
return net_info[network_name]["GlobalIPv6Address"]
|
return net_info[network_name]["GlobalIPv6Address"]
|
||||||
|
13
test/test_host-network-mode/test_proxy-host-network-mode.py
Normal file
13
test/test_host-network-mode/test_proxy-host-network-mode.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def test_forwards_to_host_network_container_1(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://host-network-1.nginx-proxy.tld:8888/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.text == "answer from port 8080\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_forwards_to_host_network_container_2(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://host-network-2.nginx-proxy.tld:8888/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.text == "answer from port 8181\n"
|
26
test/test_host-network-mode/test_proxy-host-network-mode.yml
Normal file
26
test/test_host-network-mode/test_proxy-host-network-mode.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
version: "2"
|
||||||
|
|
||||||
|
services:
|
||||||
|
host-network-1:
|
||||||
|
image: web
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: "8080"
|
||||||
|
VIRTUAL_HOST: "host-network-1.nginx-proxy.tld"
|
||||||
|
VIRTUAL_PORT: "8080"
|
||||||
|
network_mode: host
|
||||||
|
|
||||||
|
host-network-2:
|
||||||
|
image: web
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: "8181"
|
||||||
|
VIRTUAL_HOST: "host-network-2.nginx-proxy.tld"
|
||||||
|
VIRTUAL_PORT: "8181"
|
||||||
|
network_mode: host
|
||||||
|
|
||||||
|
sut:
|
||||||
|
image: nginxproxy/nginx-proxy:test
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
|
environment:
|
||||||
|
HTTP_PORT: 8888
|
||||||
|
network_mode: host
|
Loading…
x
Reference in New Issue
Block a user