快速入门
本节主要介绍 ECS 命令的基本操作,帮助用户快速掌握容器命令行使用方法。
前提条件
操作步骤
步骤一:创建容器
运行 ecs create 命令创建容器 Bundle。
[root@sylixos:/root]# ecs create /apps/ecs_demo1
步骤二:注册容器
容器 Bundle 创建成功后,通过 ecs reg 命令将其注册到操作系统中。
[root@sylixos:/root]# ecs reg /apps/ecs_demo1 ecs_demo1 Register container ecs_demo1 success!
通过 ecs 命令运查看容器状态。
[root@sylixos:/root]# ecs container list show >> ID STATUS BUNDLE FTPD TELNETD SSHD ------------------------------ -------- --------------------------------- ------- ------- ------- ecs_demo1 created /apps/ecs_demo1 running containers : 0 total containers : 1 [root@sylixos:/root]#
若在
ecs create
时指定容器 ID,此时容器会自动注册,具体命令如下所示:[root@sylixos:/root]# ecs create /apps/ecs_demo1 ecs_demo1
步骤三:启动容器
运行 ecs start 命令启动容器。
[root@sylixos:/root]# ecs start ecs_demo1 environment variables load from /etc/profile success.
通过 ecs 命令运查看容器状态。
[root@sylixos:/root]# ecs container list show >> ID STATUS BUNDLE FTPD TELNETD SSHD ------------------------------ -------- --------------------------------- ------- ------- ------- ecs_demo1 running /apps/ecs_demo1 52455 52456 running containers : 1 total containers : 1 [root@sylixos:/root]#
步骤四:登录容器环境
运行 ecs attach 命令登录容器环境。
[root@sylixos:/root]# ecs attach ecs_demo1 [root@sylixos:/root]# Please use command "shell exit" or shortcut key "Ctrl + D" to exit ecs shell. [root@sylixos_ecs:/root]# shell exit [root@sylixos:/root]#
通过 Telnet 登录容器环境。
- 运行 ecs 命令查看容器的 Telnet 端口。
[root@sylixos:/root]# ecs container list show >> ID STATUS BUNDLE FTPD TELNETD SSHD ------------------------------ -------- --------------------------------- ------- ------- ------- ecs_demo1 running /apps/ecs_demo1 52455 52456 running containers : 1 total containers : 1 [root@sylixos:/root]#
- 通过 Telent 登录容器环境。
步骤五:停止容器
运行 ecs kill 命令停止容器。
[root@sylixos:/root]# ecs kill ecs_demo1
[root@sylixos:/root]# ecs
container list show >>
ID STATUS BUNDLE FTPD TELNETD SSHD
------------------------------ -------- --------------------------------- ------- ------- -------
ecs_demo1 stopped /apps/ecs_demo1
running containers : 0
total containers : 1
[root@sylixos:/root]#
步骤六:注销容器
运行 ecs unreg 命令注销容器。
[root@sylixos:/root]# ecs unreg ecs_demo1
[root@sylixos:/root]# ecs
container list show >>
ID STATUS BUNDLE FTPD TELNETD SSHD
------------------------------ -------- --------------------------------- ------- ------- -------
running containers : 0
total containers : 0
[root@sylixos:/root]#
注意:
- 容器被注销后,若需重新启用该容器,则只需完成步骤二注册以及步骤三启动这两项操作,不必再次执行步骤一创建容器的操作。
步骤七:删除容器
运行 ecs delete 命令删除容器 Bundle。
[root@sylixos:/root]# ecs delete /apps/ecs_demo1
Delete /apps/ecs_demo1/config.json..
Delete /apps/ecs_demo1/rootfs/home..
Delete /apps/ecs_demo1/rootfs/qt..
Delete /apps/ecs_demo1/rootfs/etc/group..
Delete /apps/ecs_demo1/rootfs/etc/snmp/snmpv3_user..
Delete /apps/ecs_demo1/rootfs/etc/snmp/snmpv3_engineid..
Delete /apps/ecs_demo1/rootfs/etc/snmp..
Delete /apps/ecs_demo1/rootfs/etc/pci..
Delete /apps/ecs_demo1/rootfs/etc/profile..
Delete /apps/ecs_demo1/rootfs/etc/startup.sh..
Delete /apps/ecs_demo1/rootfs/etc/passwd..
Delete /apps/ecs_demo1/rootfs/etc/lic..
Delete /apps/ecs_demo1/rootfs/etc/hosts..
Delete /apps/ecs_demo1/rootfs/etc/shadow..
Delete /apps/ecs_demo1/rootfs/etc/ssh/sshd_config..
Delete /apps/ecs_demo1/rootfs/etc/ssh..
Delete /apps/ecs_demo1/rootfs/etc..
Delete /apps/ecs_demo1/rootfs/proc..
Delete /apps/ecs_demo1/rootfs/sbin..
Delete /apps/ecs_demo1/rootfs/bin..
Delete /apps/ecs_demo1/rootfs/lib/libfastlock.so..
Delete /apps/ecs_demo1/rootfs/lib/modules/drivers..
Delete /apps/ecs_demo1/rootfs/lib/modules..
Delete /apps/ecs_demo1/rootfs/lib/libsrtpe.so..
Delete /apps/ecs_demo1/rootfs/lib/lua/socket..
Delete /apps/ecs_demo1/rootfs/lib/lua/lxp..
Delete /apps/ecs_demo1/rootfs/lib/lua/cjson..
Delete /apps/ecs_demo1/rootfs/lib/lua/copas..
Delete /apps/ecs_demo1/rootfs/lib/lua/llthreads2..
Delete /apps/ecs_demo1/rootfs/lib/lua..
Delete /apps/ecs_demo1/rootfs/lib/libmbedcrypto.so..
Delete /apps/ecs_demo1/rootfs/lib/libcextern.so..
Delete /apps/ecs_demo1/rootfs/lib..
Delete /apps/ecs_demo1/rootfs/dev..
Delete /apps/ecs_demo1/rootfs/var/log/snmp..
Delete /apps/ecs_demo1/rootfs/var/log/cdump..
Delete /apps/ecs_demo1/rootfs/var/log..
Delete /apps/ecs_demo1/rootfs/var/tmp..
Delete /apps/ecs_demo1/rootfs/var..
Delete /apps/ecs_demo1/rootfs/usr/sbin..
Delete /apps/ecs_demo1/rootfs/usr/libexec..
Delete /apps/ecs_demo1/rootfs/usr/bin..
Delete /apps/ecs_demo1/rootfs/usr/lib/ssl/lib/engines..
Delete /apps/ecs_demo1/rootfs/usr/lib/ssl/lib..
Delete /apps/ecs_demo1/rootfs/usr/lib/ssl..
Delete /apps/ecs_demo1/rootfs/usr/lib..
Delete /apps/ecs_demo1/rootfs/usr..
Delete /apps/ecs_demo1/rootfs/tmp..
Delete /apps/ecs_demo1/rootfs/boot..
Delete /apps/ecs_demo1/rootfs/apps..
Delete /apps/ecs_demo1/rootfs/root..
Delete /apps/ecs_demo1/rootfs..
Delete /apps/ecs_demo1..
Delete /apps/ecs_demo1 success!
容器内运行应用程序
容器启动后手动运行应用程序
容器环境下手动运行应用程序的两种方法:
通过 ecs attach 命令进入容器内运行应用程序。
[root@sylixos:/root]# ecs attach ecs_demo1 [root@sylixos:/root]# Please use command "shell exit" or shortcut key "Ctrl + D" to exit ecs shell. [root@sylixos_ecs:/root]# /apps/helloecs Hello ECS! [root@sylixos_ecs:/root]#
通过 ecs exec 命令运行容器内应用程序。
[root@sylixos:/root]# ecs exec ecs_demo1 /apps/helloecs [root@sylixos:/root]# Hello ECS! [root@sylixos:/root]#
容器启动时自动运行应用程序
启动容器时自动运行应用程序两种方法:
修改容器配置文件 config.json 中 args 参数。
在容器
${Bundle}/rootfs/etc
路径下的启动脚本startup.sh
中添加应用程序。[root@sylixos:/root]# vi /apps/ecs_demo1/rootfs/etc/startup.sh /apps/helloecs &