mineshaftgap / d4m-nfs

Docker for Mac with NFS for performance improvements over osxfs
296 stars 26 forks source link

Can't mount volume directory that does not exist on host #32

Closed alanfranz closed 7 years ago

alanfranz commented 7 years ago

This is a followup to #25 (since it got closed, I supposed you didn't read my late followup); I'm rewriting everything here, btw.

If I try mounting a volume with an host directory that does not exist, I get an error, while the very same behaviour is 100% working on Linux and/or using osxfs:

AlanEnerlife-mbpro:d4m-nfs alan$ docker run -v /Users/alan/asdasdasd:/asdasdasd -it ubuntu:xenial /bin/bash
docker: Error response from daemon: Mounts denied:
The path /Users/alan/asdasdasd
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
..
AlanEnerlife-mbpro:d4m-nfs alan$

image

AlanEnerlife-mbpro:d4m-nfs alan$ cat etc/d4m-nfs-mounts.txt
/Users:/Users:0:0
/Volumes:/Volumes
/private:/private
AlanEnerlife-mbpro:d4m-nfs alan$ cat /tmp/d4m-mount-nfs.sh
ln -nsf /tmp/d4m-apk-cache /etc/apk/cache
apk update
apk add nfs-utils sntpc
rpcbind -s > /dev/null 2>&1

DEFGW=$(ip route|awk '/default/{print $3}')
FSTAB="\n\n# d4m-nfs mounts\n"

if false && ! $(grep ':/mnt' /tmp/d4m-nfs-mounts.txt > /dev/null 2>&1); then
  mkdir -p /mnt

  FSTAB="${FSTAB}${DEFGW}:/Users/alan /mnt nfs nolock,local_lock=all 0 0"
fi

if [ -e /tmp/d4m-nfs-mounts.txt ]; then
  while read MOUNT; do
    DSTDIR=$(echo "$MOUNT" | cut -d: -f2)
    mkdir -p ${DSTDIR}
    FSTAB="${FSTAB}\n${DEFGW}:$(echo "$MOUNT" | cut -d: -f1) ${DSTDIR} nfs nolock,local_lock=all 0 0"
  done < /tmp/d4m-nfs-mounts.txt
fi

if ! $(grep "d4m-nfs mounts" /etc/fstab > /dev/null 2>&1); then
    echo adding d4m nfs config to /etc/fstab:
    echo -e $FSTAB | tee /etc/fstab
else
    echo d4m nfs mounts already exist in /etc/fstab
fi

sntpc -i 10 ${DEFGW} &

sleep .5
mount -a
touch /tmp/d4m-done
AlanEnerlife-mbpro:d4m-nfs alan$ cat /tmp/d4m-nfs-mounts.txt
/Users:/Users:0:0
/Volumes:/Volumes
/private:/private
AlanEnerlife-mbpro:d4m-nfs alan$ cat /etc/exports
# d4m-nfs exports

"/Users" -alldirs -mapall=0:0 localhost
"/Volumes" -alldirs -mapall=0:0 localhost
"/private" -alldirs -mapall=0:0 localhost
if-kyle commented 7 years ago

running

docker run -v /Users/$(whoami)/asdasdasd:/asdasdasd -it ubuntu:xenial /bin/bash

Fails for me without having /Users in Preferences -> File sharing.

Are you sure this works outside of d4m, on osxfs?

The default nature for docker is to try to create the paths, thus on linux it makes sense that this works as you likely have access to your home dir.

EDIT

I see you are using etc/d4m-nfs-mounts.txt thus the reason your screenshot only has /tmp. Please ignore my above comment.

if-kyle commented 7 years ago

Please try updating etc/d4m-nfs-mounts.txt to only have the following line

/Users/alan:/mnt:0:0

re-run d4m-nfs.sh

and see if "docker run -v /Users/alan/asdasdasd:/asdasdasd -it ubuntu:xenial /bin/bash" works.

alanfranz commented 7 years ago

@if-kyle I have just tried; I experience the very same error.

alanfranz commented 7 years ago

but weren't you meaning, by chance:

"docker run -v /mnt/asdasdasd:/asdasdasd -it ubuntu:xenial /bin/bash"

?

Since you're proposing to mount my home in /mnt?

That last command, in fact, succeeds. What does not seem to succeed is something like:

docker run -v /mnt/asd123/asd123:/asdasdasd123 -it ubuntu:xenial /bin/bash

It looks like that via NFS we're just able to create ONE missing directory, not an entire directory tree. Does that make sense to you?

Mahmoudz commented 7 years ago

I'm experiencing the same error as well :)

❯ docker-compose up -d nginx mysql redis
Creating network "laradockmj5_default" with the default driver
Creating laradockmj5_mysql_1
Creating laradockmj5_redis_1
Creating laradockmj5_applications_1
Creating laradockmj5_workspace_1
Creating laradockmj5_php-fpm_1
Creating laradockmj5_nginx_1

ERROR: for nginx  Cannot start service nginx: Mounts denied: .com/docker-for-mac/osxfs/#namespaces for more info.
.
j/moubarmij/l5-code/laradock-mj5/logs/nginx
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker
ERROR: Encountered errors while bringing up the project.
if-kenn commented 7 years ago

@Mahmoudz you might be experiencing the same error as Alan, but you are quite a different setup. Please make sure to read the README, look at the examples and if you still have issues, create a new issue with all the requested information from the README.

if-kenn commented 7 years ago

@alanfranz it appears as though you are having the same problem as others, please review this from the README.md:

https://github.com/IFSight/d4m-nfs/commit/45f1628be62f91c5c7aaff9a97de931f5b5679fb

alanfranz commented 7 years ago

Hello @if-kenn , thanks for your suggestion. But it doesn't seem related to my issue. In my Docker fro mac preferences, I still have just /tmp on osxfs. I tried exporting just /Users (which seems to have no symlinks around) and I still have the same issue as in my first post:

AlanMacbook:d4m-nfs alan$ docker run -v /Users/alan/asdasdasd:/asdasdasd -it ubuntu:xenial /bin/bash
docker: Error response from daemon: Mounts denied:
The path /Users/alan/asdasdasd
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.

Debug log:

AlanMacbook:d4m-nfs alan$ cat etc/d4m-nfs-mounts.txt
# Be sure that any mounts that have been added here
# have been removed from Docker for Mac -> Preferences -> File Sharing
#
# You must supply the Mac source directory and Moby VM destination directory,
# and optionally add on user/group mapping:
#
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man5/exports.5.html
#
# <MAC_SRD_DIR>:<MOBY_VM_DST_DIR>[:MAC_UID_MAP][:MAC_GID_MAP]
#
/Users:/Users:0:0
AlanMacbook:d4m-nfs alan$ cat /tmp/d4m-mount-nfs.sh
ln -nsf /tmp/d4m-apk-cache /etc/apk/cache
apk update
apk add nfs-utils sntpc
rpcbind -s > /dev/null 2>&1

DEFGW=$(ip route|awk '/default/{print $3}')
FSTAB="\n\n# d4m-nfs mounts\n"

if false && ! $(grep ':/mnt' /tmp/d4m-nfs-mounts.txt > /dev/null 2>&1); then
  mkdir -p /mnt

  FSTAB="${FSTAB}${DEFGW}:/Users/root /mnt nfs nolock,local_lock=all 0 0"
fi

if [ -e /tmp/d4m-nfs-mounts.txt ]; then
  while read MOUNT; do
    DSTDIR=$(echo "$MOUNT" | cut -d: -f2)
    mkdir -p ${DSTDIR}
    FSTAB="${FSTAB}\n${DEFGW}:$(echo "$MOUNT" | cut -d: -f1) ${DSTDIR} nfs nolock,local_lock=all 0 0"
  done < /tmp/d4m-nfs-mounts.txt
fi

if ! $(grep "d4m-nfs mounts" /etc/fstab > /dev/null 2>&1); then
    echo adding d4m nfs config to /etc/fstab:
    echo -e $FSTAB | tee /etc/fstab
else
    echo d4m nfs mounts already exist in /etc/fstab
fi

sntpc -i 10 ${DEFGW} &

sleep .5
mount -a
touch /tmp/d4m-done
AlanMacbook:d4m-nfs alan$ cat /tmp/d4m-nfs-mounts.txt
/Users:/Users:0:0
AlanMacbook:d4m-nfs alan$ cat /etc/exports
# d4m-nfs exports

"/Users" -alldirs -mapall=0:0 localhost
if-kenn commented 7 years ago

I just did a bunch of testing. It looks like this is something out of our control at the d4m-nfs level. Docker looks to see if the volume exists, if it does not and it does exist where Docker for Mac can write to it will throw this error since it is not aware of the existence of the NFS volumes on the Mac provided d4m-nfs. So the error is a bit misleading in this context.

Bottom line is if you are looking to make directories on the fly, you are stuck with using Docker for Mac native.

alanfranz commented 7 years ago

OK. Thanks for all your support! I think it's ok, it's just good to know; maybe writing it in the README will help other people as well.