Docker + Ubuntu + Virtualbox: “volumes” directive

2019-02-17 15:11发布

问题:

Docker + Ubuntu + Virtualbox: "volumes" directive in dockerfile not working? See the solution below.

回答1:

Just testing Docker here and already in front an issue: the "volumes" directive in dockerfile seems like not working in Ubuntu -- OK in Mac and Windows. All the proccess with docker-machine and docker-compose alright and the environment ups, but the filesystem without the sharing folders.

After trying MANY things and a lot of researching with my pals, we found this issue in GitHub: "Add support to mount Linux host homedir".

Basically, the problem is the fail of Docker in mount host home dir in container. They plan to include the fix in future releases, but, meanwhile, if you need to use right now, here is what you have to do.

Open Virtualbox interface, right click in your machine, Settings > Shared Folders. You can delete whatever is filled and add a new one. In path, choose your /home and name Users (could be whatever name, but this one is for name consistency with Mac and Windows). Check automatic mounting and persistence and press "OK".

After that, you enter in your machine with docker-machine ssh [name] and you have to create a symlink to the /home of the guest from your shared home folder in docker (host already mapped):

ln -s "/Users/[username]/${d}" "/home/${d}"

From here, the mapping must be alright and you good to go! \o/

PS to frontenders: if you intend to use LiveReload in your projects, you need to run vboxmanage controlvm default natpf1 "35729,tcp,127.0.0.1,35729,,35729" in your terminal (not inside docker machine, in host) -- just once for all projects.