Vagrant chicken-and-egg: Shared folder with uid = apache user Vagrant chicken-and-egg: Shared folder with uid = apache user linux linux

Vagrant chicken-and-egg: Shared folder with uid = apache user


If you can fix the uid/gid values you can use these in the mount command - they don't have to relate to an existing user/group

I do this with a user that is later created by puppet using fixed (matching)uid / gid values

config.vm.synced_folder "foo", "/var/www/foo",   id: "foo", :mount_options => ["uid=510,gid=510"]


This is what I did:

config.vm.synced_folder "./MyApp", "/opt/MyApp", owner: 10002, group: 1007, create: trueconfig.vm.provision :shell do |shell|  shell.inline = "groupadd -g 1007 myapp;                  useradd -c 'MyApp User' -d /opt/MyApp -g myapp -m -u 10002 myapp;"end

Instead of use the user name and group (as a text) use the uid and gid. Then create the group and user with those ids. This is because the error in fact is:

mount -t vboxsf -o uid=`id -u myapp`,gid=`getent group myapp | cut -d: -f3` opt_MyApp /opt/MyApp...id: myapp: No such user

The id command was not able to recognize the user. So, switching to uid and gid the command id won't be used by vagrant.

The only warning I got with this approach is that user home directory (/opt/MyApp) already exist, but I can live with that, or you can change the useradd command to ignore the home directory if already exists.

Before that, the workaround I used is:

vagrant up; vagrant provision; vagrant reload

But, it not nice neither clean.


Ryan Sechrest has dealt extensively with this problem.

One of the presented solutions is:

Set permissions of directories to 777 and files to 666

config.vm.synced_folder "/Users/ryansechrest/Projects/Sites",   "/var/www/domains", mount_options: ["dmode=777", "fmode=666"]