How do I mount –bind inside a Docker container?

I have this container based on debian:jessie (but this is not very relevant as I had the same issue with alpine:3.3). I get to the point where I need to

mount --bind /htdocs/www /home/user/

and I get

  • Run script from host machine on Docker container with exec [closed]
  • “chfn: PAM: System Error” Intermittently in Docker Hub Builds
  • loopback in docker container cannot connect to mongo
  • distribute docker containers evenly with kubectl
  • Docker Service Separation
  • Connectivity issue to Cassandra cluster from Docker container (Java)
  • mount: permission denied

    I can’t find anything in any kernel log, and -vvv yields nothing interesting. I obviously can do this on the host (with any other pair of subtree/node). In my example above /htdocs/www is the mountpoint of a Docker volume, but it doesn’t appear like it’s of any importance, as I can’t mount --bind any pair of subtree/node inside the container.

  • Creating a Private Docker Registry with Authentication
  • Docker container exits immediately despite Service Running
  • Docker doesn't start MONGODB, and IPAddress doesn't appear, when started with other services
  • Pushing a Docker image with gcloud failed
  • How to force docker build to use devpi server for pip install command?
  • docker volume mount directory in windows
  • One Solution collect form web for “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:jessie
    root@ee0b1d5fe546:/# mkdir /mnt/test
    root@ee0b1d5fe546:/# mount --bind /home /mnt/test/

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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.