Skip to content

Instantly share code, notes, and snippets.

@adrenalinkin
Last active January 17, 2023 10:19
Show Gist options
  • Save adrenalinkin/ccd8839c02058bd11b9250e4057f66c9 to your computer and use it in GitHub Desktop.
Save adrenalinkin/ccd8839c02058bd11b9250e4057f66c9 to your computer and use it in GitHub Desktop.
Docker NFS optimization for MAC

Install docker for mac.

  • Edit /etc/nfs.conf:

     nfs.server.mount.require_resv_port = 0 
    
  • Edit /etc/exports (create if not exist):

    Execute command and Put result of command execution into /etc/exports.:

    for OSX Mojave and lower:

    echo "$HOME -alldirs -mapall=$(id -u):$(id -g) localhost"

    for OSX Catalina and higher:

    echo "/System/Volumes/Data -alldirs -mapall=$(id -u):$(id -g) localhost"
  • Restart nfsd service:

    sudo nfsd restart
  • Use nfs-volume in your docker-compose.yaml:

    # Add PROJECT_NAME into .env file to avoid collision with other projects
    volumes:
        app_volume:
            name: ${PROJECT_NAME}_app_volume
            driver: local
            driver_opts:
                type: nfs
                o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
                device: ":${PWD}"
                # for OSX Catalina
                # device: ":/System/Volumes/Data${PWD}"
    
    services:
        php:
            container_name: ${PROJECT_NAME}_php
            image: php:7.2-fpm
            volumes:
                - app_volume:/app:rw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment