How do I mount --bind inside a Docker container? How do I mount --bind inside a Docker container? docker docker

How do I mount --bind inside a Docker container?


For using the mount system call, you need the CAP_SYS_ADMIN capability. By default, Docker drops all capabilities when spawning a container (meaning that even as root, you're not allowed to do everything). See the mount(2) man page for more information.

You can start your container with the --cap-add=SYS_ADMIN flag to add this capability to your container:

root@host > docker run --rm -it --cap-add=SYS_ADMIN debian:jessieroot@ee0b1d5fe546:/# mkdir /mnt/testroot@ee0b1d5fe546:/# mount --bind /home /mnt/test/root@ee0b1d5fe546:/# 

Use this with caution. Do not run untrusted software in a privileged container.


Try with --privileged flag:

docker run --rm -it --privileged=true debianmkdir /mnt/testmount --bind /home /mnt/test/