Containers run in a specially protected namespace within the router firmware (NetCloud OS) and may only operate within this space. This is to protect the host filesystem from containers accessing and potentially corrupting the operating files and breaking the host. There are several ways to get user files into a container, depending on which services are running in the container. One method would be to run an SSH or FTP service in the container and transfer files between an external client and the container. Another method would be to run a second container with a dedicated FTP server, mount a volume between the containers on the host, and then transfer files between the two. This latter method is used mainly in development environments.
To demonstrate how volumes work in containers, the following example shows how to create a project named shared- data-test with a volume named share-data. Two redis:alpine containers will be created under the shared-data- test project and the /var/tmp directory on each container mapped to the share-data volume on each. This shared resource could be used to copy data (from a file in this example) from one container to the other.
Tip
Data on a volume is not updated with changes from a new image. To resolve this, a new project must be created; this creates a new volume that gets the changes from the new image.
Log into NetCloud Manager.
Select in the left-side navigation panel.
Select a router from the Routers page. Alternatively, to make configuration changes to a group, navigate to the Groups page and select a group.
Select and then .
Navigate to > > .
Note
See Configuring a Container for more information on setting up the new project.
Select .
Enter a name (for this example, "shared-data-test") and ensure it is enabled.
Select Compose Builder and add a new volume name. For example, "shared-data".
Select .
From the Project Builder window, select under .
Select the tab and enter the container name (redis1), an image (redis:alpine), and other information needed for the container.
Select to map the volume to the service (container).
Under Volumes, select and select the volume name created earlier from the drop-down menu (for this example, we used shared-data).
Note
Selecting the option exposes cs.sock and allows a container to communicate with its host device's Config Store.
Selecting the option allows containers to use devices connected to USB ports on the router for storage.
Append “:/var/tmp” to the end of the volume name (for example, shared-data:/var/tmp). This is where the container mounts the volume.
Select .
Repeat steps 12 through 16 to create a second container service named redis2:alpine and map the shared-data volume to it.
Select .
Navigate to and review the generated compose yaml.
Select .
Select to write the config to the router.
To verify the volume is accessible from each container, open the console to run the container exec commands and create a file under the /var/tmp directory in redis1 container. Once the file is created, log into the second container, redis2, and verify the file is visible in the /var/tmp directory. See the following for the CLI commands:
[admin@E300-dae: /]$ container list Project: shared-data-test Containers: shared-data-test_redis2_1 shared-data-test_redis1_1 [admin@E300-dae: /]$ container exec shared-data-test_redis1_1 sh /data # cd /var/tmp /var/tmp # ls /var/tmp # touch shared-file.txt /var/tmp # ls shared-file.txt /var/tmp # exit shared-data-test_redis1_1 exec done. [admin@E300-dae: /]$ [admin@E300-dae: /]$ [admin@E300-dae: /]$ container exec shared-data-test_redis2_1 sh /data # cd /var/tmp /var/tmp # ls shared-file.txt /var/tmp # /var/tmp # /var/tmp # exit shared-data-test_redis2_1 exec done. [admin@E300-dae: /]$
For more information on Docker Hub volumes, See Docker Volumes.