跳到主要内容

--cap-add使容器可以使用更多的功能

参考docker官方文档 https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities

Runtime privilege(特权) and Linux capabilities(功能)

OptionDescription
--cap-addAdd Linux capabilities
--cap-dropDrop Linux capabilities
--privilegedGive extended privileges to this container
--device=[]Allows you to run devices inside the container without the --privileged flag.

The following table lists the Linux capability options which are allowed by default and can be dropped. **

Capability KeyCapability Description
AUDIT_WRITEWrite records to kernel auditing log.
CHOWNMake arbitrary changes to file UIDs and GIDs (see chown(2)).
DAC_OVERRIDEBypass file read, write, and execute permission checks.
FOWNERBypass permission checks on operations that normally require the file system UID of the process to match the UID of the file.
FSETIDDon’t clear set-user-ID and set-group-ID permission bits when a file is modified.
KILLBypass permission checks for sending signals.
MKNODCreate special files using mknod(2).
NET_BIND_SERVICEBind a socket to internet domain privileged ports (port numbers less than 1024).
NET_RAWUse RAW and PACKET sockets.
SETFCAPSet file capabilities.
SETGIDMake arbitrary manipulations of process GIDs and supplementary GID list.
SETPCAPModify process capabilities.
SETUIDMake arbitrary manipulations of process UIDs.
SYS_CHROOTUse chroot(2), change root directory.

The next table shows the capabilities which are not granted by default and may be added.

Capability KeyCapability Description
AUDIT_CONTROLEnable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules.
AUDIT_READAllow reading audit messages from the kernel.
BLOCK_SUSPENDEmploy features that can block system suspend.
DAC_READ_SEARCHBypass file read permission checks and directory read and execute permission checks.
IPC_LOCKLock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).
IPC_OWNERBypass permission checks for operations on System V IPC objects.
LEASEEstablish leases on arbitrary files (see fcntl(2)).
LINUX_IMMUTABLESet the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags.
MAC_ADMINAllow MAC configuration or state changes. Implemented for the Smack LSM.
MAC_OVERRIDEOverride Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM).
NET_ADMINPerform various network-related operations.
NET_BROADCASTMake socket broadcasts, and listen to multicasts.
SYS_ADMINPerform a range of system administration operations.
SYS_BOOTUse reboot(2) and kexec_load(2), reboot and load a new kernel for later execution.
SYS_MODULELoad and unload kernel modules.
SYS_NICERaise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes.
SYS_PACCTUse acct(2), switch process accounting on or off.
SYS_PTRACETrace arbitrary processes using ptrace(2).
SYS_RAWIOPerform I/O port operations (iopl(2) and ioperm(2)).
SYS_RESOURCEOverride resource Limits.
SYS_TIMESet system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock.
SYS_TTY_CONFIGUse vhangup(2); employ various privileged ioctl(2) operations on virtual terminals.
SYSLOGPerform privileged syslog(2) operations.
WAKE_ALARMTrigger something that will wake up the system.

examples Both flags support the value ALL, so to allow a container to use all capabilities except for MKNOD:

$ docker run --cap-add=ALL --cap-drop=MKNOD ...

更多用法见官方文档:https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities