【问题标题】:can not ping as normal user in Docker centos image无法在 Docker centos 映像中以普通用户身份 ping
【发布时间】:2015-02-17 13:33:10
【问题描述】:

我的 Dockerfile

FROM centos
RUN useradd me
CMD su -c "ping localhost" me

我的测试命令:

$ docker build -t test .
$ docker run --rm -it test
ping: icmp open socket: Operation not permitted

$ docker run --rm -it test /bin/bash    
[root@153c87b53b53 /]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.126 ms

我的临时解决方案是https://www.centos.org/forums/viewtopic.php?t=39341

chmod 4755 /usr/bin/ping

【问题讨论】:

    标签: centos docker


    【解决方案1】:

    这不是“临时解决方案”,而是允许用户级别 ping 的实际解决方案 - 基本上 ping 需要 root 级别访问才能以原始模式打开套接字。因此,当它尝试执行此操作但未以 root 身份运行时,您会收到上述错误。

    因此,为了使其正常工作,ping 必须是 setuid root,这是您在 chmod 4755 /bin/ping 时所做的 - 这意味着当您以普通用户身份运行 ping 时,您将权限提升为 root,但 ping足够聪明,可以在打开套接字后直接将您返回给您的用户。

    所以你的 Dockerfile 可能看起来像这样:

    FROM centos
    RUN chmod 4755 /bin/ping
    RUN useradd me
    CMD su -c "ping localhost" me
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-03
      • 2021-07-19
      • 2021-12-28
      • 2017-10-11
      • 2020-05-16
      • 1970-01-01
      • 2019-01-12
      • 2017-08-09
      相关资源
      最近更新 更多