Scenarios

Updated at:

This topic describes use cases for the Elastic Container Instance (ECI) command-line client (ECI-Client).

Background information

To build cluster services, you can use ACK clusters or ACK serverless clusters with ECI. This approach helps you fully leverage ECI. However, if your business is small or you only need to deploy a few standalone applications, the ECI-Client provides a simpler way to use ECI.

The ECI-Client uses the same command syntax as Docker to manage ECI instances. If you are familiar with the Docker command line, you can quickly get started with ECI. This topic describes several typical scenarios.

Test containerized applications

If you are developing applications on ECI, you may need to frequently deploy ECI instances to test your applications. The ECI-Client makes deploying ECI instances faster and more convenient.

Assume that you have built an image named centos:8.1.1911 and uploaded it to an image repository on Docker Hub. To test whether the image works as expected, you can run the following command in the ECI-Client to quickly deploy an ECI instance.

eci run -w 5 centos:8.1.1911 sleep 3600

After the ECI instance starts, you can log on to the container in the instance using the exec command. If the instance ID is eci-uf60grb03kz2nlm2****, the command is as follows:

eci exec -ti eci-uf60grb03kz2nlm2**** bash

Train simple models

The following example uses a sample image that contains a Python program. After the container starts, the program downloads data from the internet and then uses TensorFlow to train a model. The trained model is saved to /tmp/imagenet.

eci run --name test-tensor \
--type ecs.gn6i-c4g1.xlarge \
--gpu 1 \
-w 5 \
--volume /tmp/imagenet \
registry.cn-hangzhou.aliyuncs.com/eci_open/tensorflow:1.0 \
python /home/classify_image/classify_image.py 
Note
  • Because the TensorFlow program requires a GPU, you must use the --type option to specify an ECS GPU instance type for the ECI instance. The --gpu option allocates a GPU to the container in the instance. The --volume option mounts a cloud disk to the instance to save the trained model.

  • Because this image is large, ECI needs some time to download it. You can run the eci ps command to view the instance ID, name, and status.

After the ECI instance starts, you can view the program's log output by running the eci logs command. If the instance ID is eci-uf60grb03kz2nlm2****, the command is as follows:

eci logs eci-uf60grb03kz2nlm2****

Deploy a personal website

The following example shows how to use the ECI-Client to deploy a WordPress website that requires a MySQL database. The sample images are from the official Docker Hub image repository:

  1. Deploy the MySQL database and specify the password for the root user.

    eci run -w 5 --name mysql -e MYSQL_ROOT_PASSWORD=passwd*** -tid mysql:5.7

    After the command runs successfully, the instance ID is returned. You can run the eci ps command to check the instance status. The deployment is successful when the status changes to Running. The following is a sample response:

    CG_ID                      FIRST_IMAGE   COMMAND     CREATED                     STATUS    PUBLIC_IP        NAME     
    eci-2zecsa60voctfzr2****   mysql:5.7                 2023-02-17T16:33:22+08:00   Running   101.200.XX.XX    mysql  
  2. Retrieve the private IP address of the database.

    The following command uses jq. If jq is not installed on your local machine, install it first.

    eci inspect eci-2zecsa60voctfzr2**** | jq -r .ContainerGroups[0].IntranetIp

    Expected response:

    172.16.XX.XX
  3. Deploy WordPress.

    During deployment, you can use the -e option to pass the database address, username, and password as environment variables. You can also use the -w option to assign a public IP address to the website and set the bandwidth to 5 MB.

    eci run --name wordpress \
    -e WORDPRESS_DB_HOST=172.16.XX.XX \
    -e WORDPRESS_DB_USER=root \
    -e WORDPRESS_DB_PASSWORD=passwd*** \
    -w 5 \
    -tid wordpress:4.9.8-php5.6-apache

    After the command runs successfully, the instance ID is returned. You can run the eci ps command to check the instance status. The deployment is successful when the status changes to Running. The following is a sample response:

    CG_ID                      FIRST_IMAGE                     COMMAND   CREATED                     STATUS    PUBLIC_IP        NAME     
    eci-2zeedp8bxor356b7****   wordpress:4.9.8-php5.6-apache             2023-02-17T16:39:51+08:00   Running   101.200.XX.XX    wordpress
    eci-2zecsa60voctfzr2****   mysql:5.7                                 2023-02-17T16:33:22+08:00   Running   101.200.XX.XX    mysql

    You can now view the public IP address of the WordPress instance, for example, 101.200.XX.XX. Enter http://101.200.XX.XX in a browser to access WordPress.