CLI Tutorial: Docker Volumes

Note: This document is based on Jelastic version 4.7

Docker Volumes management functionality at Jelastic allows to create a persistent local storage, designed to be not affected by various operations during container lifecycle. Creation of such a storage right inside a container helps to ensure high level of integrity and prevent loss of important data.

Using Jelastic CLI, you can set up Docker volumes in two ways:

Set Volumes via Environment Topology

The first way to create Docker volume we’ll consider is to define it right during the environment creation (or when changing its topology). So, in order to setup your local container storage, the following parameters can be used for Docker-based environments whilst executing the appropriate CLI method:
  • volumes - sets list of local volumes
  • volumeMounts - allows to configure mount points
  • volumesFrom - imports existing volumes from node on your account

Tip: This parameters can be used within your JPS manifests as well.

1. All of these parameters are to be declared within the appropriate docker section. For example, the first parameter can be set in the following way:

… "docker":{... "volumes": ["{local_volume}", "{local_volume}", ...]}

Jelastic CLI volumes parameter

Here, {local_volume} is a placeholder for the path your local volume should be placed inside a container. You can specify multiple volumes at once using comma separator.

E.g., within the image above, we create environment with the jelastic/haproxy image inside and two local volumes attached, namely: /my_volume_1 and /my_volume_2.

2. The second volumeMounts parameter has the next syntaxis:

… "docker":{... "volumeMounts" : {"{local_path}" : {"sourcePath" : "{remote_path}", "sourceNodeId" : "{node_ID}", "readOnly" : {true/false}}, ...}}

Jelastic CLi volumeMounts parameter

The highlighted data should be changed to the appropriate values:
  • {local_path} - path to the folder within nodes of the specified environment layer the mounted content should be placed at
  • {remote_path} - the required directory location at the remote container (i.e. address of source data)
  • {node_ID} - unique identifier of the node your data will be mounted from

    Note: Alternatively to the "sourceNodeId" parameter, you can also use:

    • "sourceNodeGroup" - defines environment layer, which master node will be used as a source for mount operation
    • "sourceHost" - external IP or custom domain name of the data storage server (including external one)
  • {true/false} - the appropriate values define read only or read & write rights for client nodes while operating mounted data (false by default)

As an example, using the command on image above, we’ve mounted data from the 111109 node of the used account.

3. With the last volumesFrom parameter, it’s possible to mount all the existing volumes from one node to another (i.e. copy them), e.g.:

… "docker":{... "volumesFrom":[{"sourceNodeId" : "{node_ID}", "readOnly" : {true/false}, "volumes" : ["{local_volume}", "{local_volume}", ...]}]}

Jelastic CLI volumesFrom parameter

Here:
  • {node_ID}unique identifier of the node the data should be mounted from
    Note: Alternatively, it is possible to use "sourceNodeGroup" to define environment layer, which master node will be used as a source for mount operation.
  • {true/false} - the appropriate values define read only or read & write rights for client nodes while operating mounted data (false by default)
  • {local_volume} - list of volumes to be mounted (if not specified all of them will be copied)

In such a way, using the command in the image above, we’ve added a new layer with two jelastic/tomcat8 Docker images and mounted the comprised volumes to the existing jelastic/haproxy node.

Direct Volumes Management

Jelastic provides you with a number of CLI methods, that are developed specially for volumes management and do not affect the rest of environment topology:

1. The first one is the AddDockerVolume command, which let’s you add a new volume to the existing environment:

~/jelastic/environment/control/adddockervolume --envName {env_name} --nodeId {node_ID} --path {path}
where:
  • {env_name} - domain name of the environment you’d like to modify
  • {node_ID} - unique identifier of the node in chosen environment, a new Docker volume should be added to
  • {path} - path in local filesystem to your volume directory

Jelastic CLI add Docker volume

2. The removal process is absolutely similar to the just described addition process and uses the same parameters:

~/jelastic/environment/control/removedockervolume --envName {env_name} --nodeId {node_ID} --path {path}

Jelastic CLI remove Docker volume

3. In case you need to add volumes not to a single node, but to a whole environment layer at once, the AddDockerVolumeByGroup method will be more suitable:

~/jelastic/environment/control/adddockervolumebygroup --envName {env_name} --nodeGroup {node_group} --path {path}

Here, the {node_group} parameter allows to define layer in the current environment (e.g. cp, bl, storage, etc), which nodes should be modified with a new volume.

jelastic CLI add Docker volume by group

4. Surely, you can remove a volume for the whole layer in a single command as well:

~/jelastic/environment/control/removedockervolumebygroup --envName {env_name} --nodeGroup {node_group} --path {path}

Jelastic CLI remove Docker volume by group

In such a way, using these CLI methods, you can easily take control over your Docker volumes and manage them in a matter of minutes. And in case you are in need of adding some Mount Points alongside with volumes, use the linked guide for detailed instruction.

If you face any issues while working with Jelastic CLI, feel free to appeal for our technical experts’ assistance at Stackoverflow.