Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create multi SHARED_DIRECTORY? #13

Closed
tianxiawuzhe opened this issue May 7, 2018 · 6 comments
Closed

How to create multi SHARED_DIRECTORY? #13

tianxiawuzhe opened this issue May 7, 2018 · 6 comments

Comments

@tianxiawuzhe
Copy link

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
Copy link
Owner

sjiveson commented May 7, 2018

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
Copy link
Owner

sjiveson commented May 7, 2018

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
Copy link
Author

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
Copy link
Owner

sjiveson commented May 8, 2018

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

@sjiveson
Copy link
Owner

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

@qiushaocloud
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants