大网数据广告活动
服务器运维问答

Can't ping (permission denied)

· 52CE 我爱测

I have an issue with my docker installation. For some security reasons I configured my "daemon.json" that the namespace is switched to another user ( userns-remap ). Now I have the problem that if I run a container (with switched…

问题原文

原帖链接 · Phil · CC BY-SA 4.0

I have an issue with my docker installation. For some security reasons I configured my "daemon.json" that the namespace is switched to another user (userns-remap). Now I have the problem that if I run a container (with switched user context (USER containeruser) and try to ping another one which is in the same container network I get following error:

$ ping 172.16.0.3
PING 172.16.0.3 (172.16.0.3): 56 data bytes
ping: permission denied (are you root?)

I already tried several things with AppArmor, assigning more capabilities and so on. But nothing helped to resolve that issue.

The running image is an alpine linux without any modifications.

Do you have a solution for my problem?

已采纳解答

原帖链接 · Zeitounator · CC BY-SA 4.0

TL;DR

apk add iputils

Explanation

Alpine is based on busybox which implements the linux usual commands in a single binary. If you look at the /bin directory on your base alpine image, you will see that the ping command (like others) is a symbolic link to /bin/busybox

To be ran as a normal user, ping needs the suid bit set. You could be tempted to set the suid bit on the symbolic link (i.e. chmod u+s /bin/ping). But that would actually set it on the busybox binary hence on all other commands registered as a symbolic link which would be a security breach.

Fortunately, there is an iputils package in alpine which contains an alternative version of ping. If you install it, it will replace the symbolic link with a plain binary holding the necessary permissions to be executed by everyone. Simply add the above necessary command in a RUN line in your Dockerfile.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。