Skip to content

Commit de1dce9

Browse files
authored
Detect if iptables-nft is possible (#79)
use that if it works, and fallback to iptables-legacy if not
1 parent 3778f2e commit de1dce9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

entrypoint.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
set -euo pipefail
44
c=$'\n\t'
55

6-
# since alpine version 3.19.0 iptables-nft is used by default (https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.19.0),
7-
# however this causes compatibility issues for hosts with older kernels (e.g. Windows > https://github.com/microsoft/WSL/issues/6044),
6+
# since alpine version 3.19.0 iptables-nft is used by default (https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.19.0),
7+
# however this causes compatibility issues for hosts with older kernels (e.g. Windows > https://github.com/microsoft/WSL/issues/6044),
88
# therefore we still use iptables-legacy
99
alias iptables=iptables-legacy
10+
if iptables-nft -L -n > /dev/null 2>&1; then
11+
alias iptables=iptables-nft
12+
fi
1013

1114
# --- Ensure container network capabilities ----------------------------------
1215

@@ -83,13 +86,13 @@ for forwarding_port in $PORTS
8386
do
8487
docker_container_port="${forwarding_port%%:*}"
8588
docker_host_port="${forwarding_port#*:}"
86-
89+
8790
# nft add rule nat prerouting tcp \
8891
# dport "${docker_container_port}" \
8992
# dnat to "$docker_host_ip:$docker_host_port"
9093
iptables --table nat --insert PREROUTING \
9194
--protocol tcp --destination-port "${docker_container_port/-/:}" \
92-
--jump DNAT --to-destination "$docker_host_ip:$docker_host_port"
95+
--jump DNAT --to-destination "$docker_host_ip:$docker_host_port"
9396

9497
# nft add rule nat prerouting udp \
9598
# dport "${docker_container_port}" \

0 commit comments

Comments
 (0)