Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Last active January 23, 2025 09:49
Show Gist options
  • Save seanhandley/7dad300420e5f8f02e7243b7651c6657 to your computer and use it in GitHub Desktop.
Save seanhandley/7dad300420e5f8f02e7243b7651c6657 to your computer and use it in GitHub Desktop.

Revisions

  1. seanhandley revised this gist May 30, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion setup_native_nfs_docker_osx.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ echo " | Setup native NFS for Docker |"
    echo " +-----------------------------+"
    echo ""

    echo "WARNING: This script will shut down running containers."
    echo "WARNING: This script will shut down running containers and prune docker volumes."
    echo ""
    echo -n "Do you wish to proceed? [y]: "
    read decision
  2. seanhandley revised this gist Oct 9, 2019. No changes.
  3. seanhandley revised this gist May 11, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ version: '2'
    services:
    api:
    volumes:
    - "nfsmount:#{CONTAINER_DIR}"
    - "nfsmount:${CONTAINER_DIR}"

    volumes:
    nfsmount:
  4. seanhandley revised this gist Apr 2, 2018. No changes.
  5. seanhandley revised this gist Apr 2, 2018. 1 changed file with 0 additions and 10 deletions.
    10 changes: 0 additions & 10 deletions setup_native_nfs_docker_osx.sh
    Original file line number Diff line number Diff line change
    @@ -42,16 +42,6 @@ echo "== Stopping running docker containers..."
    docker-compose down > /dev/null 2>&1
    docker volume prune -f > /dev/null

    command -v docker-machine > /dev/null
    if [ "$?" == 0 ]; then
    docker-machine stop dev > /dev/null 2>&1
    fi

    command -v docker-sync > /dev/null
    if [ "$?" == 0 ]; then
    docker-sync stop > /dev/null 2>&1
    fi

    osascript -e 'quit app "Docker"'

    echo "== Resetting folder permissions..."
  6. seanhandley created this gist Apr 2, 2018.
    13 changes: 13 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    version: '2'
    services:
    api:
    volumes:
    - "nfsmount:#{CONTAINER_DIR}"

    volumes:
    nfsmount:
    driver: local
    driver_opts:
    type: nfs
    o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
    device: ":${SOURCE_DIR}"
    2 changes: 2 additions & 0 deletions env_vars.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    export CONTAINER_DIR=/myapp
    export SOURCE_DIR=/Users/me/myapp
    81 changes: 81 additions & 0 deletions setup_native_nfs_docker_osx.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    #!/usr/bin/env bash

    OS=`uname -s`

    if [ $OS != "Darwin" ]; then
    echo "This script is OSX-only. Please do not run it on any other Unix."
    exit 1
    fi

    if [[ $EUID -eq 0 ]]; then
    echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2
    exit 1
    fi

    echo ""
    echo " +-----------------------------+"
    echo " | Setup native NFS for Docker |"
    echo " +-----------------------------+"
    echo ""

    echo "WARNING: This script will shut down running containers."
    echo ""
    echo -n "Do you wish to proceed? [y]: "
    read decision

    if [ "$decision" != "y" ]; then
    echo "Exiting. No changes made."
    exit 1
    fi

    echo ""

    if ! docker ps > /dev/null 2>&1 ; then
    echo "== Waiting for docker to start..."
    fi

    open -a Docker

    while ! docker ps > /dev/null 2>&1 ; do sleep 2; done

    echo "== Stopping running docker containers..."
    docker-compose down > /dev/null 2>&1
    docker volume prune -f > /dev/null

    command -v docker-machine > /dev/null
    if [ "$?" == 0 ]; then
    docker-machine stop dev > /dev/null 2>&1
    fi

    command -v docker-sync > /dev/null
    if [ "$?" == 0 ]; then
    docker-sync stop > /dev/null 2>&1
    fi

    osascript -e 'quit app "Docker"'

    echo "== Resetting folder permissions..."
    U=`id -u`
    G=`id -g`
    sudo chown -R "$U":"$G" .

    echo "== Setting up nfs..."
    LINE="/Users -alldirs -mapall=$U:$G localhost"
    FILE=/etc/exports
    sudo cp /dev/null $FILE
    grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE > /dev/null

    LINE="nfs.server.mount.require_resv_port = 0"
    FILE=/etc/nfs.conf
    grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE > /dev/null

    echo "== Restarting nfsd..."
    sudo nfsd restart

    echo "== Restarting docker..."
    open -a Docker

    while ! docker ps > /dev/null 2>&1 ; do sleep 2; done

    echo ""
    echo "SUCCESS! Now go run your containers 🐳"