All Products
Search
Document Center

Elastic Container Instance:Mount a NAS volume to an elastic container instance

Last Updated:Apr 01, 2026

Container storage is ephemeral — data is lost when a container stops or crashes. Mounting a File Storage NAS (NAS) volume gives your containers persistent, shared storage that survives instance deletion and scales automatically. NAS solves two common problems:

  • Data persistence: Data is stored on a remote file system, independent of any instance lifecycle.

  • Shared access: Multiple elastic container instances can mount the same NAS volume and share data, useful for workloads that need a common file store.

Prerequisites

Before you begin, ensure that you have:

  • A NAS file system. See Create a file system.

  • A mount target for the NAS file system. See Manage mount targets.

  • The NAS file system and the target elastic container instance in the same virtual private cloud (VPC).

Usage notes

  • Billing: NAS file systems are billed based on usage and support pay-as-you-go, resource plan, and storage capacity unit (SCU) billing methods. See Billing overview.

  • Data consistency: NAS is a shared storage service — one file system can be mounted to multiple instances simultaneously. If multiple instances write to the same file system, your application must handle cross-instance data synchronization.

  • Mount target deletion: Do not delete the mount target before unmounting the NAS file system. Deleting the mount target first may cause an operating system hang.

Choose a volume type

ECI supports two volume types for NAS mounts via the API. Choose based on your needs:

Volume typeUse whenSupports custom NFS options
NFS volume (NFSVolume)You need a straightforward NAS mount with basic read/write or read-only settingsNo
FlexVolume (FlexVolume)You need to specify the NFS protocol version, custom options (for example, nolock,tcp,noresvport), or subdirectoriesYes

For most standard NAS mounts, use an NFS volume. Use FlexVolume when you need Extreme NAS (which requires NFS v3 and a /share path prefix) or custom NFS mount options.

Mount a NAS volume via the API

When you call the CreateContainerGroup API operation, use Volume-related parameters to declare volumes and Container.N.VolumeMount-related parameters to mount them to containers.

Declare the volume

NFS volume

ParameterTypeRequiredExampleDescription
Volume.N.NameStringYesnas-demoName of the volume. Referenced by VolumeMount parameters.
Volume.N.TypeStringYesNFSVolumeSet to NFSVolume.
Volume.N.NFSVolume.ServerStringYes3f9cd4**-na*.cn-shanghai.nas.aliyuncs.comDomain name of the NAS mount target.
Volume.N.NFSVolume.PathStringYes/sharePath to the NFS volume.
Volume.N.NFSVolume.ReadOnlyBooleanNofalsetrue: read-only. false: read and write. Default: false.

FlexVolume

ParameterTypeRequiredExampleDescription
Volume.N.NameStringYesnas-demoName of the volume. Referenced by VolumeMount parameters.
Volume.N.TypeStringYesFlexVolumeSet to FlexVolume.
Volume.N.FlexVolume.DriverStringYesalicloud/nasDriver type. Set to alicloud/nas to mount a NAS file system.
Volume.N.FlexVolume.OptionsStringYes{"server":"...","path":"/share","vers":"3","options":"nolock,tcp,noresvport"}JSON string with mount configuration. See the sub-parameters below.

FlexVolume.Options sub-parameters:

KeyRequiredDescription
serverYesDomain name of the NAS mount target.
pathNoSubdirectory of the NAS file system. Must start with /. If the subdirectory does not exist, it is created automatically. For Extreme NAS, the path must start with /share. Defaults to the root directory if not set.
versNoNFS protocol version. Use 3 (NFS v3). Extreme NAS only supports NFS v3.
optionsNoCustom mount options. Comma-separated, for example nolock,tcp,noresvport.

Mount the volume to a container

After declaring volumes, mount them to containers using the following parameters:

ParameterTypeRequiredExampleDescription
Container.N.VolumeMount.N.NameStringYesnas-demoName of the volume to mount. Must match a Volume.N.Name value.
Container.N.VolumeMount.N.MountPathStringYes/dataContainer directory to mount the volume to. Data in this directory is overwritten by the volume data.
Container.N.VolumeMount.N.SubPathStringNo/subSubdirectory within the volume. Use this to mount different subdirectories of the same volume to different containers.
Container.N.VolumeMount.N.ReadOnlyBooleanNofalseWhether the mount directory is read-only. Default: false.
Container.N.VolumeMount.N.MountPropagationStringNoNoneMount propagation setting. Default: None. See below for valid values.

MountPropagation values:

ValueBehavior
NoneThe volume mount does not receive subsequent mounts on this volume or its subdirectories.
HostToContainerThe volume mount receives all subsequent mounts on this volume or its subdirectories.
BidirectionalLike HostToContainer, plus all mounts created by the container are propagated back to the host and to all containers sharing the same volume.
Volumes can also be mounted to init containers. Use InitContainer instead of Container in the parameter names.

Mount a NAS volume in the console

  1. Go to the Elastic Container Instance buy page and start creating a container group.

  2. In the Container Group Configurations section of the Basic Settings step, click Advanced Settings.

  3. In the Storage section, click the NAS Persistence tab, then click Add.

  4. Configure the NAS volume:

    • Name: Name of the NAS volume.

    • Mount Point: Mount target of the NAS file system.

    • Path: Path within the NAS file system.

    • Read-only: Select to restrict access to read-only. Read and write is the default.

    nas

  5. In the Container Configurations section, select a container and click Advanced Settings.

  6. Turn on Storage, then click Add to mount the volume you configured.

    nas2

To mount volumes to multiple containers, select each container and repeat steps 5-6.

Example: share data between two instances

This example creates two instances that share the same NAS volume, demonstrating data persistence across instance lifecycles.

Step 1: Create Instance A and mount the NAS volume using NFSVolume.

ContainerGroupName=test-nas-a
SecurityGroupId=sg-bp1daxpbz9lzpvvc****
VSwitchId=vsw-bp1gds63lmlm7ib05****
# Declare the NAS volume
Volume.1.Name=nas-demo
Volume.1.Type=NFSVolume
Volume.1.NFSVolume.Server=3f9cd4****-na***.cn-shanghai.nas.aliyuncs.com
Volume.1.NFSVolume.Path=/share
# Mount the volume to a container
Container.1.Name=nginx
Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2
Container.1.VolumeMount.1.Name=nas-demo
Container.1.VolumeMount.1.MountPath=/data-a

Step 2: Connect to Instance A and write a file to /data-a. See Connect to an elastic container instance.

nas3

Step 3: Delete Instance A.

Step 4: Create Instance B and mount the same NAS volume using FlexVolume.

ContainerGroupName=test-nas-b
SecurityGroupId=sg-bp1daxpbz9lzpvvc****
VSwitchId=vsw-bp1gds63lmlm7ib05****
# Declare the NAS volume
Volume.1.Name=nas-demo
Volume.1.Type=FlexVolume
Volume.1.FlexVolume.Driver=alicloud/nas
Volume.1.FlexVolume.Options={"server":"3f9cd4****-na***.cn-shanghai.nas.aliyuncs.com","path": "/share"}
# Mount the volume to a container
Container.1.Name=nginx
Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2
Container.1.VolumeMount.1.Name=nas-demo
Container.1.VolumeMount.1.MountPath=/data-b

Step 5: Connect to Instance B and verify that the file written by Instance A is visible in /data-b.

nas4

Because Instance A and Instance B share the same NAS volume, and NAS provides persistent storage, the file survives the deletion of Instance A and is accessible from Instance B.

What's next