Skip to content

How to create multi SHARED_DIRECTORY? #13

Closed
@tianxiawuzhe

Description

@tianxiawuzhe

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 ?

Activity

sjiveson

sjiveson commented on May 7, 2018

@sjiveson
Owner

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

sjiveson commented on May 7, 2018

@sjiveson
Owner

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

tianxiawuzhe commented on May 8, 2018

@tianxiawuzhe
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

sjiveson commented on May 8, 2018

@sjiveson
Owner

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

sjiveson

sjiveson commented on Nov 19, 2018

@sjiveson
Owner

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

qiushaocloud

qiushaocloud commented on Jan 18, 2023

@qiushaocloud

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sjiveson@tianxiawuzhe@qiushaocloud

        Issue actions

          How to create multi SHARED_DIRECTORY? · Issue #13 · sjiveson/nfs-server-alpine