This topic describes the usage scenarios of the Command Line Interface (CLI) client of Elastic Container Instance (ECI-Client).
Background information
If you want to build cluster applications, we recommend that you use Container Service for Kubernetes (ACK) clusters or ACK Serverless clusters to fully utilize Elastic Container Instance. If your business is small or you want to deploy only a few standalone applications, ECI-Client allows you to use Elastic Container Instance more easily.
ECI-Client uses the same syntax to manage elastic container instances as Docker. If you are familiar with the Docker CLI, you can quickly get started with Elastic Container Instance. This topic describes common usage scenarios of ECI-Client.
Test container applications
If you are developing an application based on Elastic Container Instance, you may need to frequently deploy elastic container instances to check whether the applications run as expected. In this case, you can use ECI-Client to conveniently deploy elastic container instances.
For example, you build a centos:8.1.1911 image and upload the image to a Docker Hub image repository. To test whether the image works as expected, you can run the following command in ECI-Client to deploy an elastic container instance:
eci run -w 5 centos:8.1.1911 sleep 3600After you start an elastic container instance, you can run the exec command to log on to containers in the instance. If the instance ID is eci-uf60grb03kz2nlm2****, run the following command:
eci exec -ti eci-uf60grb03kz2nlm2**** bashTrain a simple model
In the following example, a sample image that contains a Python program is used. After you start the container, the program downloads data from the Internet and uses TensorFlow to train the data. The trained data is stored in the /tmp/imagenet directory.
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.pyTensorFlow programs rely on GPUs. You must use the --type parameter to specify a GPU-accelerated instance type of Elastic Compute Service (ECS) for the elastic container instance. You must also use the --gpu parameter to allocate GPUs to containers in the instance, and use the --volume parameter to mount a disk to the elastic container instance. The disk stores the training results.
After you start the elastic container instance, you can run the eci logs command to view the log output of TensorFlow programs. If the instance ID is eci-uf60grb03kz2nlm2****, run the following command:
eci logs eci-uf60grb03kz2nlm2****This image is large. Elastic Container Instance requires a period of time to download the image. You can run the eci ps command to view the ID, name, and status of the elastic container instance.
Deploy a personal website
In the following example, ECI-Client is used to deploy a WordPress website that uses a MySQL database. The sample image is from a DockerHub image repository:
WordPress: wordpress:4.9.8-php5.6-apache
MySQL: mysql:5.7
Deploy the MySQL database and configure a password for the root user.
eci run -w 5 --name mysql -e MYSQL_ROOT_PASSWORD=passwd*** -tid mysql:5.7After you run the command, an instance ID is generated. You can run the
eci pscommand to check the instance status. If the instance status changes to Running, the MySQL database is deployed. The following output is returned: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 mysqlObtain the internal IP address of the MySQL database.
In the following example, a
jqcommand is run to obtain the internal IP address of the MySQL database. If nojqcommand is available on the on-premises device, you must first install the jq command sets.eci inspect eci-2zecsa60voctfzr2**** | jq -r .ContainerGroups[0].IntranetIpExpected output:
172.16.XX.XXDeploy WordPress.
You can use the environment variable
-eto pass in the address, username, and password of the MySQL database. You can also use-wto assign a public IP address to the WordPress website and set the bandwidth of the website 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-apacheAfter you run the command, an instance ID is generated. You can run the
eci pscommand to check the instance status. If the instance status changes to Running, the WordPress website is deployed. The following output is returned: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 mysqlYou can view the public IP address of the WordPress website in the output. In this example, the public IP address is
101.200.XX.XX. Enterhttp://100.100.XX.XXin your browser to access the WordPress website.