New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic implementation of IPv6 for IPv6 docker networks #2437
base: main
Are you sure you want to change the base?
Conversation
@Murazaki are IPv6 only Docker network a possibility ? Last time I checked it wasn't, but that was a while (ie a few years) ago. |
It works, and I'm using it right now. Though there is a couple of tricks to it. Here's a lengthy explanation that I used to set it up. |
You might also have to be ready to dive a bit more into iptables on your server, to make sure local ipv6 addresses are properly routed. |
I've tried to create an IPv6 only Docker network with the instructions you provided but did not manage to, whatever I do Docker always affect an IPv4 subnet to my network. This seems to be possible with Podman, but the same solution does not work with Docker. Could you provide a Regardless of this, I have two small issues with this PR:
Suggested changes: --- nginx.tmpl 2024-05-15 17:19:23.000000000 +0200
+++ nginx.mod.tmpl 2024-05-15 17:26:06.000000000 +0200
@@ -92,31 +92,30 @@
{{- end }}
{{- /*
* Do not emit multiple `server` directives for this container if it
- * is reachable over multiple networks. This avoids accidentally
- * inflating the effective round-robin weight of a server due to the
- * redundant upstream addresses that nginx sees as belonging to
+ * is reachable over multiple networks or multiple IP stacks. This avoids
+ * accidentally inflating the effective round-robin weight of a server due
+ * to the redundant upstream addresses that nginx sees as belonging to
* distinct servers.
*/}}
- {{- if $ip }}
+ {{- if or $ip $ipv6 }}
# {{ .Name }} (ignored; reachable but redundant)
{{- continue }}
{{- end }}
# {{ .Name }} (reachable)
{{- if and . .IP }}
{{- $ip = .IP }}
- {{- else }}
- # /!\ No IPv4 for this network!
{{- end }}
{{- if and . .GlobalIPv6Address }}
{{- $ipv6 = .GlobalIPv6Address }}
- {{- else }}
- # /!\ No IPv6 for this network!
+ {{- end }}
+ {{- if and (empty $ip) (empty $ipv6) }}
+ # /!\ No IPv4 or IPv6 for this network!
{{- end }}
{{- else }}
# (none)
{{- end }}
# IPv4 address: {{ if $ip }}{{ $ip }}{{ else }}(none usable){{ end }}
- # IPv6 address: {{ if $ipv6 }}{{ $ipv6 }}{{ else }}(none usable){{ end }}
+ # IPv6 address: {{ if $ipv6 }}{{ $ipv6 }}{{ if $ip }} (ignored; reachable but redundant){{ end }}{{ else }}(none usable){{ end }}
{{- $_ := set $ "ip" $ip }}
{{- $_ := set $ "ipv6" $ipv6 }}
{{- end }}
@@ -330,8 +329,7 @@
{{- end }}
{{- if $ip }}
server {{ $ip }}:{{ $args.port }};
- {{- end }}
- {{- if $ipv6 }}
+ {{- else if $ipv6 }}
server [{{ $ipv6 }}]:{{ $args.port }};
{{- end }}
{{- end }} This result in this upsteam block for a dual stack container: upstream whoami.example {
# Container: nginx-proxy-whoami-1
# networks:
# nginx-proxy_default (reachable)
# IPv4 address: 172.31.0.2
# IPv6 address: fd00:cafe:face:feed::2 (ignored; reachable but redundant)
# exposed ports: 8000/tcp
# default port: 8000
# using port: 8000
server 172.31.0.2:8000;
} |
Ok you are right, unless anything has changed, docker networks are either ipv4 or "ipv4 and ipv6', which is a difference with Podman, that authorizes ipv4, ipv6, and "ipv4 and ipv6" networks. I don't see major issues with the changes you mentioned, I'm gonna test them and push them if everything goes well. |
Okay it does deactivate ipv6 though if you have ipv4 addresses. What if we want to use IPv6 rather than IPv4 ? |
I was thinking about that, maybe we could introduce a Out of curiosity, what would be the use cases for preferring IPv6 on a dual stack Docker network ? |
I won't argue around IPv6 benefits in the local network. |
This comment was marked as outdated.
This comment was marked as outdated.
This works. do you want me to push it ? |
Nope, I made a mistake on that version, I think it won't work on IPv6 only networks. I'm working on another version and adding tests (but I won't be able to test IPv6 only networks as I don't use Podman). |
Ok, I got pretty much everything except documentation on this branch. Could you take a look at it and test it ? If everything is okay for you, I'll push the commits here. |
Just adds IPv6 as upstream IP if available. Might come in handy for people that rely on IPv6 only docker networks.