【发布时间】:2022-02-14 16:50:23
【问题描述】:
我已经为此奋斗了一段时间!给定以下 Dockerfile,如果我不使用 RUN iptables... 行,然后在正在运行的 docker 容器中手动执行它们,它们就可以正常工作。但如果我将它们留在 Dockerfile 中,我会收到权限错误。
FROM ubuntu
RUN apt-get update
RUN apt-get install -y iptables
RUN iptables -I INPUT -p tcp --dport 27015 -j ACCEPT
RUN iptables -A INPUT -i eth0 -j QUEUE
docker build 的输出给出:
[+] Building 0.4s (7/8)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 199B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:latest 0.0s
=> [1/5] FROM docker.io/library/ubuntu 0.0s
=> CACHED [2/5] RUN apt-get update 0.0s
=> CACHED [3/5] RUN apt-get install -y iptables 0.0s
=> ERROR [4/5] RUN iptables -I INPUT -p tcp --dport 27015 -j ACCEPT 0.3s
------
> [4/5] RUN iptables -I INPUT -p tcp --dport 27015 -j ACCEPT:
#7 0.256 getsockopt failed strangely: Operation not permitted
------
executor failed running [/bin/sh -c iptables -I INPUT -p tcp --dport 27015 -j ACCEPT]: exit code: 1
但如果我使用:
FROM ubuntu
RUN apt-get update
RUN apt-get install -y iptables
Docker 构建完成,然后我运行映像:
docker run -i -t --cap-add NET_RAW --cap-add NET_ADMIN 094d0bb9befb
容器打开,在命令提示符下我可以输入上面的 iptables 规则。它们被接受并完全按照我的要求工作。
有什么想法可以直接从 Dockerfile 应用这些 iptable 规则吗?
【问题讨论】:
-
?但是为什么要在 RUN 中设置 iptables?
标签: linux docker ubuntu iptables