For using mount
, you'll need the CAP_SYS_ADMIN
capability, which is dropped by Docker when creating the container.
There are several solutions for this:
- Start the container with the
--cap-add sys_admin
flag. This causes Docker to retain the CAP_SYS_ADMIN
capability, which should allow you to mount a NFS share from within the container. This might be a security issue; do not do this in untrusted containers. [A previous version of this answer suggested using the --privileged=true
to retain all capabilities, thanks to @earcam for the suggestion to use --cap-add
instead].
Mount the NFS share on the host and pass it into the container as a host volume:
you@host > mount server:/dir /path/to/mount/point
you@host > docker run -v /path/to/mount/point:/path/to/mount/point
Use a Docker volume plugin (like the Netshare plugin) to directly mount the NFS share as a container volume:
you@host > docker run
--volume-driver=nfs
-v server/dir:/path/to/mount/point
centos
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…