How I use Docker on my Mac to get better performance
If you ever used Docker on a Mac you know that there is a real problem in term of performance, accessing files from macOS’s file system can be really slow. There is some workaround like docker-sync but I will not talk about this one here.
The solution used here is quite simple, running Linux in a virtual machine and mounting Linux’s File System on the host via NFS. Your code live entirely in Linux and you can access it from your host for your IDE, you can also SSH to your VM to get access to the shell.
In my case I’m using VMWare Fusion has hypervisor for my Linux VM, Ubuntu as Linux distro, I will not explain how to install Linux in a VM but talking about the problem during installation of the “stack”.
Getting IP Address and gateway of your VM
So we need to know what is the IP Address of your virtual machine, VMware gives an address via DHCP to your VM, to get it you can type “ip address” in your VM shell
Installing Docker
So after installing Ubuntu on the VM you can install Docker, if you never did this before you can follow this step by step guide.
Getting the IP of the host
Just connect to your VM through ssh, then disconnect, then connect again and you will get the IP of your host just after login.
Please note that normally the address is the same as the gateway of your VM, that’s depend on the hypervisor.
Installing NFS in the VM
On Ubuntu it’s simple just use the command above, then you have to edit the file “/etc/exports” with your home folder (or the folder you want to get access from the host) and the IP address of the host
After that just do a simple “sudo exportfs -a” to your change to take effect
The permissions and userID problem
On macOS the first user (wich us not root) has an id of 501, on Linux the “same” first user has an id of 1001, these ids are used in file permission, so to simplify the permissions management between the host and the VM it could be great to use the same id.
To do so you have to login to you VM as root (and the current user has to be completely logged of) then
Access the VM file from the host
To access the VM file from the host you can mount your NFS share via
You can now access files from the VM from the folder “dockerbox” on your Mac
Access your “web virtual host” from host
Just edit /etc/hosts on the mac and add a line with your custom hostname and the IP of the VM like the screenshot below
Bonus: another way to access files from the host
If you use Visual Studio Code the Remote Development Extension works with this method.