Dockerfile无法复制步骤

发布于 2025-01-29 13:07:41 字数 1924 浏览 3 评论 0原文

我遵循某些步骤获取curl'https://api.ipify.org?format=json'使用Redsocksiptables 但是,当我尝试通过复制步骤来容器化它时,它会在我在Entrypoint中应用iPtables规则的一部分失败。SH告诉我我没有许可执行此操作,并且curl为我提供了系统。 IP,我如何容器化它(有一个特定原因我没有设置环境变量代理,因此必须是redsocks和iptables)

我的dockerfile

FROM ubuntu:latest 
RUN apt update 
RUN apt-get install -qy redsocks 
RUN apt-get install -qy iptables 
RUN apt-get install -qy iptables-persistent 
RUN apt install curl -qy
RUN apt-get install sudo -qy
COPY . /code 
RUN rm -f /etc/redsocks.conf 
RUN ln -s /code/redsocks.conf /etc/redsocks.conf 
RUN cp /code/entrypoint.sh /entrypoint.sh 
USER root

ENTRYPOINT [ "sh", "/entrypoint.sh"] 

entrypoint.sh


echo "Restarting redsocks and redirecting traffic via iptables"
/etc/init.d/redsocks restart
iptables -t nat -N REDSOCKS
iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

iptables -t nat -A REDSOCKS -p tcp --dport 80 -j REDIRECT --to-ports 12345
iptables -t nat -A REDSOCKS -p tcp --dport 443 -j REDIRECT --to-ports 12345
iptables -t nat -A REDSOCKS -p tcp --dport 11371 -j REDIRECT --to-ports 12345

iptables -t nat -A OUTPUT -p tcp -j REDSOCKS

iptables -t nat -A PREROUTING -p tcp --dport 11371 -j REDSOCKS
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDSOCKS
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDSOCKS

echo "Check IP: "

curl 'https://api.ipify.org?format=json'
echo "-----------------------------------------------------------------------------"
exit

i followed certain steps to get curl 'https://api.ipify.org?format=json' to show the proxy IP using redsocks and iptables but when i try to containerize it by replicating the steps, it fails in the part where i apply iptables rules in entrypoint.sh telling me i dont have permission to do so and curl gives me the system ip, how can i containerize it (there is a particular reason i am not setting environment variable proxy, hence redsocks and iptables are a must)

My Dockerfile

FROM ubuntu:latest 
RUN apt update 
RUN apt-get install -qy redsocks 
RUN apt-get install -qy iptables 
RUN apt-get install -qy iptables-persistent 
RUN apt install curl -qy
RUN apt-get install sudo -qy
COPY . /code 
RUN rm -f /etc/redsocks.conf 
RUN ln -s /code/redsocks.conf /etc/redsocks.conf 
RUN cp /code/entrypoint.sh /entrypoint.sh 
USER root

ENTRYPOINT [ "sh", "/entrypoint.sh"] 

entrypoint.sh


echo "Restarting redsocks and redirecting traffic via iptables"
/etc/init.d/redsocks restart
iptables -t nat -N REDSOCKS
iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

iptables -t nat -A REDSOCKS -p tcp --dport 80 -j REDIRECT --to-ports 12345
iptables -t nat -A REDSOCKS -p tcp --dport 443 -j REDIRECT --to-ports 12345
iptables -t nat -A REDSOCKS -p tcp --dport 11371 -j REDIRECT --to-ports 12345

iptables -t nat -A OUTPUT -p tcp -j REDSOCKS

iptables -t nat -A PREROUTING -p tcp --dport 11371 -j REDSOCKS
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDSOCKS
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDSOCKS

echo "Check IP: "

curl 'https://api.ipify.org?format=json'
echo "-----------------------------------------------------------------------------"
exit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2025-02-05 13:07:41

答案很简单,只需要docker运行 - 私有的图像>

Answer was simple, just had to docker run --privileged <image>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文