简介
在上篇中我们实现了stop命令,停止正在运行的容器,本篇将实现rm命令,删除已经停止的容器
源码说明
同时放到了Gitee和Github上,都可进行获取
本章节对应的版本标签是:5.6,防止后面代码过多,不好查看,可切换到标签版本进行查看
代码实现
实现该功能的主要思路如下:
这部分的实现可以说非常简单了,主要是找到容器的配置文件,将配置文件删除即可
因为我们的ps命令就是读取指定目录下的容器配置信息命令,进行容器列表展示的
我们把对应的容器的配置信息目录一删,就完事了
rm命令添加
在main.go中添加相关的命令:
func main() {
......
app.Commands = []cli.Command{
command.InitCommand,
command.RunCommand,
command.CommitCommand,
command.ListCommand,
command.LogCommand,
command.ExecCommand,
command.StopCommand,
command.RemoveCommand,
}
......
}
在main_command.go中添加相关的命令:
var RemoveCommand = cli.Command{
Name: "rm",
Usage: "remove container",
Action: func(context *cli.Context) {
if len(context.Args()) < 1 {
log.Errorf("missing container name")
return