Docker Community Forums

Share and learn in the Docker community.

Mounting a network share as a volume: permissions

docker

(Martin Aspeli) #1

I’m running the official owncloud image. This is basically a PHP application running under Apache that lives in /var/www/html. It writes (potentially quite a lot of) data to /var/www/html/data. It runs as the user www-data (UID 33).

I’m running Docker 1.9.1 on OSX using docker-machine. Everything should be completely up to date.

I want to mount a directory from my NAS onto /var/www/html/data so that the data is stored on my NAS and not locally. I’ve done this with a mount in docker-compose.

There are two problems with this:

  • With docker-machine on OSX, anything outside /Users isn’t mountable by default (or rather, the mount comes from the VM, not OSX). I tried to work around this by symlinking /Volumes/backup/owncloud (the intended target) to ~/docker/owncloud and mounting this.
  • I get a Permission Denied error in owncloud because it can’t write to the relevant directory, due to the change in ownership. I also think the symlinking gets in the way of trying to chown the directory to UID 33 (which doesn’t exist on the Mac or the NAS).

What is the best way to achieve this?

Thanks,
Martin


(Martin Aspeli) #2

I found a solution, somewhat hacky but understandable.

This dance is kind of tricky. We ultimately want to map a folder on the NAS
as seen by the Mac, to the data directory in the owncloud container. As an
added complication, this folder has to be seen by the container as being owned
by uid 33, because that’s what Apache happens to be running as.

The general approach is to mount the NAS drive on /Volumes/backup on the Mac,
configure a shared folder in VirtualBox so that VirtualBox sees this, but mount
it in VirtualBox in such a way that all files are owned by uid 33, and then use
this as the volume mount in Docoker.

  • Mount /Volumes/backup from NAS in OSX

  • Create folders on the NAS, writeable as user under which VirtualBox is running:

    $ mkdir /Volumes/backup/owncloud
    $ mkdir /Volumes/backup/owncloud/data
    $ mkdir /Volumes/backup/owncloud/config

  • In VirtualBox, map /Volumes/backup/owncloud as a shared folder

    $ VBoxManage controlvm default acpipowerbutton
    $ VBoxManage sharedfolder add default --name owncloud --hostpath /Volumes/backup/owncloud --automount
    $ VBoxManage startvm default --type headless

    $ docker-machine ssh default
    $ sudo vi /mnt/sda1/var/lib/boot2docker/bootlocal.sh

    mkdir -p /Volumes/backup/owncloud
    mount -t vboxsf -o defaults,uid=33,gid=id -g docker,umask=007 owncloud /Volumes/backup/owncloud

    $ sudo sh /mnt/sda1/var/lib/boot2docker/bootlocal.sh

  • In future, make sure /Volumes/backup is always mounted before starting Docker.