CLI Tutorial: Docker Container Redeploy

The Docker-based environments are entirely supported by the command-line interface and, thus, are fully operational via terminal. As an example, we’ll show how to redeploy an image with another tag for a single container or for the entire group of similar containers at once.

1. At first, let’s get the list of supported tags for the desired template:

~/jelastic/environment/control/getdockertags --image {template_name} [--userName {login}] [--password {password}]
  • {template_name} - the full identifier of the image, deployed inside a container
  • {login} and {password} - optional parameters, required in case of a private repository usage

Tip: If the appropriate image is located within the Registry Hub, the registry hostname can be skipped (as in our case - tutum/apache-php). Otherwise, i.e. if working with private repository, it should be obligatory specified at the beginning of the image name.

CLI get Docker tags

According to the image above, in our case there’re only two available image versions: latest and staging.

2. Next, you need to get the unique identifiers of the nodes with the corresponding image running. The command below will hand out this data:

~/jelastic/environment/control/getenvinfo --envName {env_name} | grep -B 5 {image} | grep id

Here, the added grep filters help to quickly get the required containers’ ID: the first one will find all {image} references in the obtained response (leaving the necessary number of lines above for the required information inclusion), while the second filter is applied to sort the remained text for the id matches.

CLI get containers id

As you can see, there are two containers with the template we’ve requested.

3. Now, select the container you’d like to update and run the following command to initiate this process:

~/jelastic/environment/control/redeploycontainerbyid --envName {env_name} --nodeId {node_id} --tag {tag}
  • {env_name} - the corresponding environment name
  • {node_id} - identifier of the node, that should be redeployed
  • {tag} - an image tag your node will be updated to

Note: In case you need to redeploy multiple containers within an environment layer, the next method should be used:

~/jelastic/environment/control/redeploycontainersbygroup --envName {env_name} --nodeGroup {group_id} --tag {tag} [--sequential {true/false}]

Here, beside the parameters we’ve already considered, two other options are used:

  • {group_id} - node group identifier; can be found using the command from the 2nd step with the grep -A 30 {image} | grep nodeGroup filters applied
  • sequential - a non-obligatory option (defined with the {true/false} value), that corresponds to the same-named redeployment type, where all of the containers in a group are updated one-by-one. This allows the remaining nodes to continue handling incoming requests while the update is run, for ensuring the service availability.

CLI Docker redeploy method

The process can take several minutes, so just wait for it to be completed. The eventually received response will include the versions an image was deployed from/to and duration of the operation itself.