在 Dockerfile 中更改网络设置 (net.ipv4.ip_default_ttl)(或者,理想情况下,对于任何容器)

Change network settings (net.ipv4.ip_default_ttl) in Dockerfile (or, ideally, for any container)

我想将每个 docker 容器(包括那些在 docker build 命令期间启动的容器)的 TTL 从 64 更改为 65。

我目前的做法是添加命令

RUN echo 65 >/proc/sys/net/ipv4/ip_default_ttl

到 Dockerfile 的开头,但这给了我错误

mount: /proc/sys: permission denied


如何更改 TTL,以便在 docker build 期间使用 TTL 65?

# Dockerfile

# command to change TTL
RUN ???
# this should executes as TTL is 65
RUN curl google.com

不建议直接从 /proc/sys 更改配置。

尝试更改 iptables

 RUN iptables -t mangle -A POSTROUTING -j TTL —ttl-set 65