我希望你能在Docker容器中使用iptables将8080端口转发到80端口。在构建过程中,我遇到了错误消息,如下所示。
以下是Dockerfile:
这是输出结果:
以下是Dockerfile:
FROM fedora
RUN whoami && \
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
这是输出结果:
[~]# docker build -t temp /home/edfromhadria/Documents/Docker/temp/.
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM fedora
---> 834629358fe2
Step 1 : RUN whoami && iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
---> Running in 95046cf959bf
root
iptables v1.4.21: can't initialize iptables table `nat': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
INFO[0001] The command [/bin/sh -c whoami && iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080] returned a non-zero code: 3
谢谢您提前提供的任何帮助。
iptables
没有意义,因为iptables
命令修改本地网络命名空间的配置,该命名空间是短暂的,并且将在处理Dockerfile中特定的RUN
命令后被丢弃。当您docker run
一个镜像时,您正在创建一个具有自己一组iptables规则的新网络命名空间。通常,在Docker容器内修改iptables配置是错误的做法。如果您有其他问题,请在StackOverflow上开启一个新的问题。 - larsks