I found a solution to solve the problem and I can use cap_net_admin
in swarm mode.
You can modify the runtime source code to add the capabilities that you need (it will be a local default setting).
For example I added the CAP_NET_ADMIN
to my runtime (used nvidia-container-runtime
)
wanyvic/nvidia-container-runtime.
After that I rebuilt it, started a container (use swarm mode), input: capsh --print
and CAP_NET_ADMIN can be found:
root@25303a54ebb3:/# capsh --print
Current:=cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_admin,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap+eip
Bounding set =cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_admin,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap
Securebits: 00/0x0/1'b0
secure-noroot: no (unlocked)
secure-no-suid-fixup: no (unlocked)
secure-keep-caps: no (unlocked)
uid=0(root)
gid=0(root)
groups=
But this method is not good.
I also can't set cap_add
or cap_drop
in docker-compose.yml
, but I can't find a way to solve it.