Skip to content

Instantly share code, notes, and snippets.

@christopher-hopper
Last active January 18, 2022 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopher-hopper/e01870988d6cbeabaa412bc3052cb9f3 to your computer and use it in GitHub Desktop.
Save christopher-hopper/e01870988d6cbeabaa412bc3052cb9f3 to your computer and use it in GitHub Desktop.
macOS Amazee.io Drupal example Docker Compose override

macOS Amazee.io Drupal example Docker Compose override

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.

macOS overrides

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.

Step 1: Export an NFS shared folder

  1. Change directory to your project root folder.

    cd ~/project/example
    
  2. 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
    
  3. 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
    
  4. Restart the nfs daemon.

    sudo nfsd restart
    

Step 2: Create a folder for Drupal managed files

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.

  1. Change directory to your project root folder.

    cd ~/project/root
    
  2. Create a Drupal public files folder.

    mkdir -p ./local/files
    

Step 3: Override the Docker Compose volumes

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.

  1. Copy the provided override file into place

    cp docker-compose.macos-big-sur.override.yml docker-compose.override.yml
    
  2. Restart the Docker Compose containers

    docker-compose down --volumes
    docker-compose up -d --force-recreate
    
---
version: '2.3'
x-volumes: &nfs-volumes
volumes:
- nfs_app_data:/app
- nfs_files_data:/app/docroot/sites/default/files
volumes:
nfs_app_data:
driver: local
driver_opts:
type: nfs
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
device: ":/System/Volumes/Data${PWD}"
nfs_files_data:
driver: local
driver_opts:
type: nfs
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
device: ":/System/Volumes/Data${PWD}/local/files"
services:
cli:
<<: *nfs-volumes
nginx:
<<: *nfs-volumes
php:
<<: *nfs-volumes
chrome:
<<: *nfs-volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment