【问题标题】:Change network settings (net.ipv4.ip_default_ttl) in Dockerfile (or, ideally, for any container)更改 Dockerfile 中的网络设置 (net.ipv4.ip_default_ttl)(或者,理想情况下,对于任何容器)
【发布时间】:2018-07-24 16:51:59
【问题描述】:

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

我目前的做法是添加命令

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

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

mount: /proc/sys: 权限被拒绝


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

# Dockerfile

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

【问题讨论】:

  • 您正在尝试从容器更改内核设置,但这是行不通的。我可能会在 PREROUTING 上使用 iptables 来做到这一点。

标签: docker dockerfile docker-networking docker-build


【解决方案1】:

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

尝试改用iptables

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 2019-07-23
    • 2013-10-23
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多