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

Run nmap in a Docker container as a non-admin user

· 52CE 我爱测

I'd like to run the Nmap tool in a Docker container but not with the default root user account. I already set the (hopefully) right capabilities via setcap. Unfortunately, I get only the "operation not permitted" error when I try…

问题原文

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

I'd like to run the Nmap tool in a Docker container but not with the default root user account. I already set the (hopefully) right capabilities via setcap. Unfortunately, I get only the "operation not permitted" error when I try to run it.

This is my docker file:

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'

RUN microdnf install nmap which
RUN setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip $(which nmap)

USER 1001

CMD ["nmap", "--privileged", "-sU", "localhost"]

Any idea on how to fix this?

已采纳解答

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

The issue here is "cap_net_admin".

In order to use/set this capability inside a container, the container must be run with the "NET_ADMIN" capability.

# docker run --cap-add NET_ADMIN <...>

Or simply omitting "cap_net_admin" from your setcap statement should work.

However, to run nmap the way you want, you many only need the "cap_net_raw" capability.

Reducing your dockerfile setcap command to:

RUN setcap cap_net_raw+eip $(which nmap)

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

资料来源与适用范围

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

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

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