macOS Docker use NFS Volume to get a better performance
macOS Docker NFS Volume
Why volumes on macOS work so slow? Docker For Mac runs the docker server within the virtual machine. The host machine shares the file system with the VM using osxfs. According to the documentation:
There are a number of issues with the performance of directories bind-mounted with osxfs. In particular, writes of small blocks, and traversals of large directories are currently slow. Additionally, containers that perform large numbers of directory operations, such as repeated scans of large directory trees, may suffer from poor performance.
My blog project based on Hexo(with next theme) consist of lots of files. Docker needs to keep in sync tons of files between the host machine and the container.
The docker-compose allows defining the NFS volume that can be mounted to the container. The only thing you need to do is to configure and expose your NFS server.
If you want to mount volumes from NFS, you need to expose selected directories in /etc/export file.
First edit the /etc/exports file. If it doesn’t exist, which was my case, create it and eidt:
Edit /etc/nfs.conf to tell the NFS daemon to allow connections from any port. This is necessary as Docker NFS connections can be blocked.
Restart NFS to take .
sudo nfsd restart
Check NFS service status.
sudo nfsd status
Now we are going to configure your docker-compose.yml so that the volumes are made via NFS. Below is a simple example that can be easily adapted to the project you are working on:
You see we have a volume called nfsmount, which can be called anything you want, which has some extra parameters for your volume.
That done, you can now upload your containers and see the huge difference this one will bring to you.
docker-compose run app bash
 Slow docker on Mac? Use NFS! | Yii Academy - https://www.yiiacademy.com.br/en/2020/04/30/slow-docker-on-mac-use-nfs/
 Speed up docker using NFS volumes – FINGO Blog - https://blog.fingo.pl/speed-up-docker-using-nfs-volumes/