Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit f45d995

Browse files
DzeryCZtonivdv
authored andcommitted
Add support for WSL with HaneWIN NFS server (#97)
Add support for WSL with haneWIN NFS server
1 parent d3b1e31 commit f45d995

File tree

2 files changed

+118
-25
lines changed

2 files changed

+118
-25
lines changed

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# Docker Machine NFS
22

3+
## Requirements
4+
5+
* [Docker Machine](https://docs.docker.com/machine/) 0.5.0+
6+
7+
## Mac OS X 10.9+
8+
39
Activates [NFS](https://en.wikipedia.org/wiki/Network_File_System) for an
410
existing boot2docker box created through
511
[Docker Machine](https://docs.docker.com/machine/).
612

7-
## Requirements
813
:warning: There can be an issue with the NFS under Mac OS X High Sierra (see issue [#79](https://github.com/adlogix/docker-machine-nfs/issues/79) for more info) :warning:
914

10-
* Mac OS X 10.9+
11-
* [Docker Machine](https://docs.docker.com/machine/) 0.5.0+
15+
## Windows 10 with WSL
16+
17+
* [Install WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
18+
* [Install VirtualBox](https://www.virtualbox.org/wiki/Downloads)
19+
* [Setup Docker-machine for WSL](https://www.paraesthesia.com/archive/2018/09/20/docker-on-wsl-with-virtualbox-and-docker-machine/)
20+
* [Install haneWIN NFS server](https://hanewin.net/nfs-e.htm)
21+
* [Install `docker-machine-nfs`](#standalone)
22+
* Mount drives under root (e.g. `/c`) - [Can be configured in `/etc/wsl.conf` - `automount`](https://devblogs.microsoft.com/commandline/automatically-configuring-wsl/)
23+
* Tested with these attributes: `docker-machine-nfs MACHINE-NAME --shared-folder=/c/Users/ --mount-opts="rw,vers=3,tcp,nolock,noacl,async"`
1224

1325
## Install
1426

@@ -37,6 +49,9 @@ brew install docker-machine-nfs
3749

3850
## Usage
3951

52+
* Create `docker-machine` as usual
53+
* Run `docker-machine-nfs`
54+
4055
```sh
4156

4257

@@ -73,7 +88,7 @@ Examples:
7388
7489
> Configure the /var/www folder with NFS and the options '-alldirs -maproot=0'
7590
76-
$ docker-machine-nfs test --mount-opts="noacl,async,nolock,vers=3,udp,noatime,actimeo=1"
91+
$ docker-machine-nfs test --mount-opts="noacl,async,nolock,nfsvers=3,udp,noatime,actimeo=1"
7792
7893
> Configure the /User folder with NFS and specific mount options.
7994
@@ -83,7 +98,19 @@ Examples:
8398
8499
```
85100
101+
## Troubleshooting
102+
103+
- **Failed to mount on WSL**
104+
```
105+
Allow following exe's in "Windows Firewall" or any other firewall software used
106+
Directory -- c:/Program Files/nfsd
107+
- pmapd.exe
108+
- nfssrv.exe
109+
- nfsd.exe
110+
```
111+
86112
## Credits
87113
88-
Heavily inspired by @[mattes](https://github.com/mattes) ruby version
114+
* Heavily inspired by @[mattes](https://github.com/mattes) ruby version
89115
[boot2docker-nfs.rb](https://gist.github.com/mattes/4d7f435d759ca2581347).
116+
* @[DzeryCZ](https://github.com/DzeryCZ) added support for Windows with WSL

docker-machine-nfs.sh

100755100644
Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# The MIT License (MIT)
44
# Copyright © 2015 Toni Van de Voorde <[email protected]>
@@ -76,7 +76,7 @@ Examples:
7676
7777
> Configure the /var/www folder with NFS and the options '-alldirs -maproot=0'
7878
79-
$ docker-machine-nfs test --mount-opts="noacl,async,nolock,vers=3,udp,noatime,actimeo=1"
79+
$ docker-machine-nfs test --mount-opts="noacl,async,nolock,nfsvers=3,udp,noatime,actimeo=1"
8080
8181
> Configure the /User folder with NFS and specific mount options.
8282
@@ -91,21 +91,21 @@ EOF
9191
# @args: error-message
9292
echoError ()
9393
{
94-
echo "\033[0;31mFAIL\n\n$1 \033[0m"
94+
printf "\033[0;31mFAIL\n\n$1 \033[0m\n"
9595
}
9696

9797
# @info: Prints warning messages
9898
# @args: warning-message
9999
echoWarn ()
100100
{
101-
echo "\033[0;33m$1 \033[0m"
101+
printf "\033[0;33m$1 \033[0m\n"
102102
}
103103

104104
# @info: Prints success messages
105105
# @args: success-message
106106
echoSuccess ()
107107
{
108-
echo "\033[0;32m$1 \033[0m"
108+
printf "\033[0;32m$1 \033[0m\n"
109109
}
110110

111111
# @info: Prints check messages
@@ -119,7 +119,7 @@ echoInfo ()
119119
# @args: property-message
120120
echoProperties ()
121121
{
122-
echo "\t\033[0;35m- $1 \033[0m"
122+
printf "\t\033[0;35m- $1 \033[0m\n"
123123
}
124124

125125
# @info: Checks if a given property is set
@@ -207,8 +207,14 @@ parseCli()
207207
esac
208208
done
209209

210+
if [ "$(isWsl)" = "true" ]; then
211+
local default_shared_foder="/c/Users"
212+
else
213+
local default_shared_foder="/Users"
214+
fi
215+
210216
if [ ${#prop_shared_folders[@]} -eq 0 ]; then
211-
prop_shared_folders+=("/Users")
217+
prop_shared_folders+=("${default_shared_foder}")
212218
fi;
213219

214220
echoInfo "Configuration:"
@@ -273,7 +279,7 @@ getMachineDriver ()
273279
# @info: Loads mandatory properties from the docker machine
274280
lookupMandatoryProperties ()
275281
{
276-
echoInfo "Lookup mandatory properties ... "
282+
echoInfo "Lookup mandatory properties ... \t\t"
277283

278284
prop_machine_ip=$(docker-machine ip $1)
279285

@@ -337,7 +343,7 @@ lookupMandatoryProperties ()
337343
echoError "Could not find the virtualbox net name!"; exit 1
338344
fi
339345

340-
prop_nfshost_ip=$(VBoxManage list hostonlyifs |
346+
prop_nfshost_ip=$(VBoxManage list hostonlyifs | tr -d '\r' |
341347
grep "${prop_network_id}$" -A 3 | grep IPAddress |
342348
cut -d ':' -f2 | xargs);
343349
if [ "" = "${prop_nfshost_ip}" ]; then
@@ -348,7 +354,7 @@ lookupMandatoryProperties ()
348354
}
349355

350356
# @info: Configures the NFS
351-
configureNFS()
357+
configureNFSUnix()
352358
{
353359
echoInfo "Configure NFS ... \n"
354360

@@ -394,6 +400,32 @@ configureNFS()
394400
echoSuccess "\t\t\t\t\t\tOK"
395401
}
396402

403+
configureNFSWsl()
404+
{
405+
echoInfo "Configure NFS ... \n"
406+
407+
local nfsdPath=$(sc.exe qc nfsserver | grep BINARY_PATH_NAME | awk '{split($0,a," : "); print a[2]}' | awk '{sub("nfsd.exe","",$0);}1' | awk '{sub("\\","/",$0);}1')
408+
local wslnfsdPath=$(wslpath -a "$nfsdPath" | tr -d '\r')
409+
wslnfsdPath+="exports"
410+
411+
if [ ! -f "$wslnfsdPath" ]; then
412+
echoError "Configuration file was not found in $wslnfsdPath, please check installation of haneWin server"
413+
exit 1
414+
fi
415+
416+
for shared_folder in "${prop_shared_folders[@]}"
417+
do
418+
local wsl_shared_folder=$(wslpath -w $shared_folder)
419+
echo "$wsl_shared_folder -alldirs -exec -mapall:1000,1000 #Added by docker-machine-nfs" >> "$wslnfsdPath"
420+
done
421+
422+
echoProperties "$(net.exe stop nfsserver)"
423+
echoProperties "$(net.exe start nfsserver)"
424+
425+
echoInfo "NFS server ... \t\t\t\t"
426+
echoSuccess "OK"
427+
}
428+
397429
# @info: Configures the VirtualBox Docker Machine to mount nfs
398430
configureBoot2Docker()
399431
{
@@ -409,8 +441,15 @@ configureBoot2Docker()
409441
# render bootlocal.sh and copy bootlocal.sh over to Docker Machine
410442
# (this will override an existing /var/lib/boot2docker/bootlocal.sh)
411443

412-
local bootlocalsh='#!/bin/sh
413-
sudo umount /Users'
444+
local bootlocalsh="#!/bin/sh"
445+
446+
if [ "$(isWsl)" = "true" ]; then
447+
bootlocalsh="${bootlocalsh}
448+
sudo umount /c/Users"
449+
else
450+
bootlocalsh="${bootlocalsh}
451+
sudo umount /Users"
452+
fi
414453

415454
for shared_folder in "${prop_shared_folders[@]}"
416455
do
@@ -419,7 +458,7 @@ configureBoot2Docker()
419458
done
420459

421460
bootlocalsh="${bootlocalsh}
422-
sudo /usr/local/etc/init.d/nfs-client start"
461+
sudo /usr/local/etc/init.d/nfs-client start"
423462

424463
for shared_folder in "${prop_shared_folders[@]}"
425464
do
@@ -430,8 +469,8 @@ configureBoot2Docker()
430469
local file="/var/lib/boot2docker/bootlocal.sh"
431470

432471
docker-machine ssh $prop_machine_name \
433-
"echo '$bootlocalsh' | sudo tee $file && sudo chmod +x $file && sync" > /dev/null
434-
472+
"echo '$bootlocalsh' | sudo tee $file && sudo chmod +x $file && sync" < /dev/null > /dev/null
473+
435474
sleep 2
436475

437476
echoSuccess "OK"
@@ -456,7 +495,7 @@ isNFSMounted()
456495
{
457496
for shared_folder in "${prop_shared_folders[@]}"
458497
do
459-
local nfs_mount=$(docker-machine ssh $prop_machine_name "sudo mount" |
498+
local nfs_mount=$(docker-machine ssh $prop_machine_name "sudo mount" < /dev/null |
460499
grep "$prop_nfshost_ip:$(resolveHostPath "$shared_folder") on")
461500
if [ "" = "$nfs_mount" ]; then
462501
echo "false";
@@ -490,7 +529,7 @@ verifyNFSMount()
490529
# @info: Displays the finish message
491530
showFinish()
492531
{
493-
echo "\033[0;36m"
532+
printf "\033[0;36m"
494533
echo "--------------------------------------------"
495534
echo
496535
echo " The docker-machine '$prop_machine_name'"
@@ -499,9 +538,32 @@ showFinish()
499538
echo " ENJOY high speed mounts :D"
500539
echo
501540
echo "--------------------------------------------"
502-
echo "\033[0m"
541+
printf "\033[0m"
542+
}
543+
544+
# WSL
545+
546+
# @return: 'true', if platform is WSL; else 'false'
547+
isWsl()
548+
{
549+
if [ "$(uname -r | grep 'Microsoft')" != "" ]; then
550+
echo "true"
551+
else
552+
echo "false"
553+
fi
503554
}
504555

556+
if [ "$(isWsl)" = "true" ]; then
557+
printf "\033[0;32mPlaform WSl detected\033[0m\n"
558+
559+
# @info: translate docker-machine to .exe
560+
function docker-machine()
561+
{
562+
docker-machine.exe "$@"
563+
}
564+
export -f docker-machine
565+
fi
566+
505567
# END _functions
506568

507569
setPropDefaults
@@ -513,7 +575,7 @@ checkMachineRunning $prop_machine_name "$prop_timeout"
513575

514576
lookupMandatoryProperties $prop_machine_name "$prop_timeout"
515577

516-
if [ "$(isNFSMounted)" = "true" ] && [ "$prop_force_configuration_nfs" = false ]; then
578+
if [ "$(isNFSMounted)" = "true" ] && [ "$prop_force_configuration_nfs" = "false" ]; then
517579
echoSuccess "\n NFS already mounted." ; showFinish ; exit 0
518580
fi
519581

@@ -525,7 +587,11 @@ echoProperties "NFSHost IP: $prop_nfshost_ip"
525587

526588
echo #EMPTY LINE
527589

528-
configureNFS
590+
if [ "$(isWsl)" = "true" ]; then
591+
configureNFSWsl
592+
else
593+
configureNFSUnix
594+
fi
529595

530596
configureBoot2Docker
531597
restartDockerMachine

0 commit comments

Comments
 (0)