package service import ( "errors" ) type IContainer interface { // Image 运行环境及配置的基础目录或镜像位置 Image() string //获取container的根路径 GetContainerRoot() string //初始化此用户的容器运行环境 Init(cId string) error //启动container Start(cId string) error //停止container Stop(cId string) error //重启container Restart(cId string) error //备份容器中的用户数据,防止删除后需要再还原 BakData(cId string) error //删除container Destroy(cId string) error //监控是否有容器未创建或启动 watch() } const ( TypeContainerDir = iota TypeContainerDocker ) var ContainerNotFound = errors.New("Container not found") // NewContainer 目前container管理器有dir和docker两种模式 func NewContainer(typ int) IContainer { var c IContainer switch typ { case TypeContainerDir: c = &DirContainerImpl{} case TypeContainerDocker: c = &DockerImpl{} } go c.watch() return c }