Volumes - Containers-Advanced-Configuration-Guide/Volumes

Containers Advanced Configuration Guide

ft:locale
en-US
ft:sourceName
Paligo_Prod
Document Type
Configuration Guide

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.

  1. Log into NetCloud Manager.

  2. Select Devices in the left-side navigation panel.

  3. Select a router from the Routers page. Alternatively, to make configuration changes to a group, navigate to the Groups page and select a group.

  4. Select Configuration and then Edit.

  5. Navigate to SYSTEM > ContainersProjects.

    Note

    See Configuring a Container for more information on setting up the new project.Configuring a Container

  6. Select Add.

  7. Enter a name (for this example, "shared-data-test") and ensure it is enabled.

    image8.jpeg
  8. Select Compose Builder and add a new volume name. For example, "shared-data".

    image9.jpeg
  9. Select Save.

  10. From the Project Builder window, select Add under Services.

  11. Select the Basic tab and enter the container name (redis1), an image (redis:alpine), and other information needed for the container.

    image10.jpeg
  12. Select Volumes & Devices to map the volume to the service (container).

  13. Under Volumes, select Add and select the volume name created earlier from the drop-down menu (for this example, we used shared-data).

    Note

    Selecting the Config Store option exposes cs.sock and allows a container to communicate with its host device's Config Store.

    Selecting the USB Storage option allows containers to use devices connected to USB ports on the router for storage.

  14. Append “:/var/tmp” to the end of the volume name (for example, shared-data:/var/tmp). This is where the container mounts the volume.

  15. Select Save.

    image11.jpeg

    Repeat steps 12 through 16 to create a second container service named redis2:alpine and map the shared-data volume to it.

    image12.png
  16. Select Save.

  17. Navigate to Project Configuration > Compose and review the generated compose yaml.

    image13.png
  18. Select Save.

  19. Select Commit to write the config to the router.

  20. 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.