Override Docker Compose volumes in an Amazee.io Drupal example to use NFS mounts.
This can substantially improve the disk I/O performance when running disk heavy
operations inside Docker containers. Specifically, we're looking to improve
performance for operations like php composer install
and composer update
.
Performance in the Docker cli container on macOS is poor due to known issues with Docker Desktop for macOS and its shared volume performance. We can address this using NFS mounts and a local Docker Compose override file.
-
Change directory to your project root folder.
cd ~/project/example
-
Export the folder as an NFS volume.
echo "\"$(df "$PWD" | awk 'END { print $NF }')$PWD\" -alldirs -mapall=$(id -u):$(id -g) localhost" \ | sudo tee -a /etc/exports
-
Allow NFS connections on any port, as required by Docker.
sudo sed -i '.bak' '/nfs.server.mount.require_resv_port/d' \ /etc/nfs.conf sudo tee -a /etc/nfs.conf <<EOHD nfs.server.mount.require_resv_port = 0 EOHD
-
Restart the nfs daemon.
sudo nfsd restart
Create a folder inside your project root that will not be deleted or removed by
git clean
or any clean-up scripts you use. Typically this folder will be
ignored by Git.
-
Change directory to your project root folder.
cd ~/project/root
-
Create a Drupal public files folder.
mkdir -p ./local/files
To override the Drupal example or project Docker Compose we create our override file. This allows us to use our custom volumes locally without impacting other developers who are using Linux or Windows.
-
Copy the provided override file into place
cp docker-compose.macos-big-sur.override.yml docker-compose.override.yml
-
Restart the Docker Compose containers
docker-compose down --volumes docker-compose up -d --force-recreate