Rancher provides the ability to select NFS volumes as a storage option for containers.
A NFS server has to be installed prior to launching the Rancher NFS driver. For example, to install a NFS server on Ubuntu 16.04, you can use the following commands.
sudo apt-get update sudo apt-get install nfs-kernel-server
On the server, you will need to export a base directory. First, you’ll need to create the shared directory.
sudo mkdir /nfs sudo chown nobody:nogroup /nfs
Modify the exports file (
After all the modifications, restart the NFS kernel server.
sudo systemctl restart nfs-kernel-server
The Rancher NFS driver can connect to Amazon EFS. When using Rancher NFS driver with Amazon EFS, all hosts in the environment will need to be EC2 instances, deployed in the same availability zone as where EFS is deployed.
When setting up an environment template, you can select the Rancher NFS catalog item so that it will be available in any environment created from that environment template.
Alternatively, if you already have an environment set up, you can select and launch Rancher NFS from the catalog.
Note: Some storage services may not be compatible with some container orchestration types (i.e. Kubernetes). Environment templates will restrict which ones are compatible based on orchestration, but all options are available from the catalog.
In order to launch Rancher NFS, you will need to specify the following:
nfsversoption, it will be ignored.
When creating volumes using the Rancher NFS driver, there are several options that can be used to customize the volume. These options are key value pairs that can be added in the UI as a driver options or in compose files under the
host): NFS host
export): When the volume is configured with the host and export, no subfolder is created; the root export directory is mounted.
exportBase): By default, the volume can be configured with the host and export base, which creates a uniquely named subfolder on the NFS server.
mntOptions): Comma delimited list of default mount options.
After Rancher NFS is launched in Rancher, you will need to create the volumes in the NFS in Infrastructure -> Storage before using the volume in a service.
Once a volume is created in the UI, services can start using the shared storage. when creating a service, in the Volumes tab, provide a volume and a volume driver.
The volume will be in the same syntax as Docker,
<volume_name>:</path/in/container>. Docker volumes default to mount in read-write mode, but you can set it to be mounted read-only by adding the
:ro at the end of the volume.
The volume driver will be the name of the storage driver, which is the name of the stack. By default, the Rancher NFS storage driver will be
After the Rancher NFS infrastructure stack has been launched, you can start creating volumes in a compose file.
Volumes can be specified as part of a compose file under the
volumes key. Each volume can be associated with one or more services in the same file.
Note: This functionality is only available when using a compose file in v2 format.
In this example, we are creating a NFS volume while creating services that use this volume. All services in this stack will share the same volume.
version: '2' services: foo: image: alpine volumes: - bar:/data volumes: bar: driver: rancher-nfs
After creating an EFS file system on AWS, you can launch the Rancher NFS driver to use this EFS file system. Since Amazon EFS is only reachable internally, only EC2 instances in the same availability zone can reach this EFS, therefore EC2 instances should be added to Rancher prior to creating the storage driver.
You can launch Rancher NFS with the following options for example: