sjiveson / nfs-server-alpine

A handy Alpine Linux based NFS Server image running NFS v4 only, over TCP on port 2049
https://hub.docker.com/r/itsthenetwork/nfs-server-alpine/
GNU General Public License v3.0
295 stars 187 forks source link

How to create multi SHARED_DIRECTORY? #13

Closed tianxiawuzhe closed 6 years ago

tianxiawuzhe commented 6 years ago

I'm sorry to bother you. I want to create more than one share directory. How can i share multi directories in one docker container ?

sjiveson commented 6 years ago

Hey @tianxiawuzhe,

No problem. You'll want to edit the confd/tmpl/exports.tmpl file and add one or more additional lines, with each one using a dedicated environment variable unique from SHARED_DIRECTORY. For example: SHARED_DIRECTORY_2 and SHARED_DIRECTORY_3.

Then simply feed in your their values via additional -e parameters and -v volume mounts. Here's an example:

{{getenv "SHARED_DIRECTORY"}} {{if getenv "PERMITTED"}}{{getenv "PERMITTED"}}{{else}}*{{end}}({{if getenv "READ_ONLY"}}ro{{else}}rw{{end}},fsid=0,{{if getenv "SYNC"}}sync{{else}}async{{end}},no_subtree_check,no_auth_nlm,insecure,no_root_squash)
{{getenv "SHARED_DIRECTORY_2"}} {{if getenv "PERMITTED"}}{{getenv "PERMITTED"}}{{else}}*{{end}}({{if getenv "READ_ONLY"}}ro{{else}}rw{{end}},fsid=0,{{if getenv "SYNC"}}sync{{else}}async{{end}},no_subtree_check,no_auth_nlm,insecure,no_root_squash)
{{getenv "SHARED_DIRECTORY_3"}} {{if getenv "PERMITTED"}}{{getenv "PERMITTED"}}{{else}}*{{end}}({{if getenv "READ_ONLY"}}ro{{else}}rw{{end}},fsid=0,{{if getenv "SYNC"}}sync{{else}}async{{end}},no_subtree_check,no_auth_nlm,insecure,no_root_squash)
sjiveson commented 6 years ago

Your docker run command would then look something like this:

docker run -d --name nfs --privileged -v /some/where/fileshare:/nfsshare -v /some/where/fileshare:/nfsshare2 -v /some/where/fileshare:/nfsshare3 -e SHARED_DIRECTORY=/nfsshare -e SHARED_DIRECTORY_2=/nfsshare2 -e SHARED_DIRECTORY_3=/nfsshare3 itsthenetwork/nfs-server-alpine:latest
tianxiawuzhe commented 6 years ago

Thank you very much. My code like this in confd/tmpl/exports.tmpl:

{{getenv "SHARED_DIRECTORY"}} {{if ... rw{{end}},fsid=0,{{if getenv "SYNC"}} ... ) {{getenv "SHARED_DIRECTORY01"}} {{if ... rw{{end}},{{if getenv "SYNC"}} ... ) {{getenv "SHARED_DIRECTORY02"}} {{if ... rw{{end}},{{if getenv "SYNC"}} ... ) {{getenv "SHARED_DIRECTORY03"}} {{if ... rw{{end}},{{if getenv "SYNC"}} ... )

The first line says : SHARED_DIRECTORY is a root dir, and 01 to 03 are sub directories which could not set 'fsid=0'. And some parameters in run command:

-h nasserver -e SHARED_DIRECTORY=/nfsroot/
-e SHARED_DIRECTORY01=/nfsroot/vol1 -e SHARED_DIRECTORY02=/nfsroot/vol2 -e SHARED_DIRECTORY03=/nfsroot/vol3

Then in another container, can mount server's /nfsroot/vol1 to local dir '/home/vol_1/' like this:

mount -t nfs4 [IP or hostname]:/vol1 /home/vol_1/

Thanks again.

sjiveson commented 6 years ago

You're welcome. Thanks for posting back with details that may help others.

sjiveson commented 6 years ago

Hey. I've made some changes to help support this, please see the latest README.

qiushaocloud commented 1 year ago

如果是多个不同目录怎么弄,比如 /nfs01 和 /nfs02