Data in containers is temporarily stored in disks and is deleted when containers are released. Data cannot be shared between containers. If you want to share the data or persistently store the data, you can mount a volume to a container to manage the data. This topic describes how to mount a network-attached storage (NAS) file system as a volume to an elastic container instance (ECI) when you create the instance. This way, you can store the data that is generated when the instance runs and share the data with other containers or instances.
Prerequisites
ECI and Resource Access Management (RAM) are activated. Your RAM role is granted the required permissions.
NoteIf you create an ECI instance as a RAM user, you must grant the required permissions to the RAM user. For more information, see Grant permissions to a RAM user.
vSwitches and a VPC are created in the region where you want to create an ECI instance.
For information about the regions and zones where ECI is available, see Regions and zones.
For information about how to create a VPC and vSwitch, see Create and manage a VPC and Create and manage a vSwitch.
NoteWe recommend creating multiple vSwitches. This way, you can select multiple vSwitches to implement the multi-zone feature when you create an ECI instance. This improves the success rate of instance creation.
A security group is created. For more information, see Create a security group.
Security groups serve as virtual firewalls that provide Stateful Packet Inspection (SPI) and packet filtering capabilities to isolate security domains on the cloud. Each ECI instance must belong to a security group. For more information, see Assign a security group to an ECI instance.
Procedure
This section describes the key configurations and steps of creating an ECI instance and mounting a NAS volume. For some parameters, only the minimum required or default configurations are used.
Log on to the File Storage NAS console.
Create a NAS file system and add a mount target. For more information, see Create a file system and Manage mount targets.
Go to the Elastic Container Instance buy page.
-
Configure the basic information of the instance.
-
Specify the billing method and type of the instance.
Use the default settings. The billing method is pay-as-you-go, and the instance type is regular instance.
Select the region in which you want to create the ECI instance.
Select a VPC and a vSwitch.
We recommend that you select multiple vSwitches to implement the multi-zone feature. The system preferentially creates the instance in a zone where inventory resources are sufficient.
-
Select a security group. Security group rules allow or deny access for ECI instances to the public internet or within the VPC, and control access between IP addresses.
NoteIf you want to access ECI instances in a VPC over the Internet, you must enable corresponding ports in the security group to which the ECI instances belong. For more information, see Add a security group rule.
-
-
Configure the container group.
Specify specifications for the container group.
In this example, the instance is created by using vCPU and memory specifications. This creation mode provides better elasticity and resource provisioning capabilities. If your business requires special specifications, such as GPU-accelerated instances, you can specify corresponding Elastic Compute Service (ECS) instance types. For more information, see Specify ECS instance types to create an ECI instance.
Enter a name for the container group.
-
Click Advanced Settings.
-
In the Storage section, click the NAS Persistence tab.
-
Click Add to configure the NAS volume.
Name: the name of the NAS volume.
Mount Point: the mount target of the NAS file system.
Path: the path to mount the NAS file system.
Read-only: the read and write permissions on data in the NAS file system. By default, data in the NAS file system can be read and written. You can select Read-only based on your requirements.
-
Configure a container.
Enter a name for the container.
-
Select an image and an image tag.
On the Common Images tab, select eci_open/nginx and choose the 1.14.2 version.
Note-
The default image pulling policy (imagePullPolicy) is IfNotPresent, meaning the system first tries to use a local image and pulls a new one only if a local copy is unavailable.
Images whose source is ALI_HUB are stored in Alibaba Cloud image repositories. By default, the images are pulled over VPCs.
-
Unfold Advanced Settings of the container.
-
Enable Storage and then click Add.
-
Select the NAS volume that you added to the container group and enter the mount path in the container.
For example, select nas-volume, set the mount path to
/test, and select Read-only if needed.
-
Click Confirm Configuration.
-
Confirm the instance configuration, read and select the terms of service, and then click Confirm Order.
After the instance is created, you can view it on the Container Group page. Click the instance ID to view its details.
View results
-
Click the instance ID to view its details. On the Volumes tab, you can view information about the mounted NAS volume.
In this example, the NAS volume is named nas-volume, the Server is the NAS file system's mount target address, the Path is
/test, and ReadOnly isfalse. -
Click the Workbench Connection tab. After you configure the logon information and connect to the instance, you can access the mount path.
Elastic Container Service! root@nas-test:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test tmp usr var root@nas-test:/# cd test root@nas-test:/test#