BX21
BX21

Reputation: 461

how can a docker container check if it has a capability

For example, suppose I have a container which needs the NET_ADMIN capability (keepalived as a container for example).

How can I check, when the container is run, that the capability is actually provided, so that I can add a log / throw an error?

Upvotes: 5

Views: 4607

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

You can commands to check the capabilities

$ capsh --print | grep "Current:" | cut -d' ' -f3 | grep -q cap_net_admin
$ echo $?
0

$ capsh --print | grep "Current:" | cut -d' ' -f3 | grep -q cap_net_admins
$ echo $?
1

Below command shows all available capabilities for a container

$ capsh --print | grep "Current:" | cut -d' ' -f3 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

Upvotes: 8

Related Questions