cmd

package
v0.0.0-...-be3b871 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_EXEC_PID = "ddocker_pid"
	ENV_EXEC_CMD = "ddocker_cmd"
)

Variables

View Source
var CommitCommand = cli.Command{
	Name:  "commit",
	Usage: "commit a container into image",
	Action: func(ctx *cli.Context) error {
		if len(ctx.Args()) < 2 {
			return errors.New("missing containerID or image name")
		}

		containerID := ctx.Args().Get(0)
		image := ctx.Args().Get(1)
		commitContainer(containerID, image)
		return nil
	},
}
View Source
var ExecCommand = cli.Command{
	Name:  "exec",
	Usage: "exec a command into container",
	Action: func(ctx *cli.Context) error {

		if os.Getenv(ENV_EXEC_PID) != "" {
			logrus.Infof("pid callback pid %d", os.Getgid())
			return nil
		}

		if len(ctx.Args()) < 2 {
			return fmt.Errorf("expect shell command is: [ddocker exec containerID command]")
		}

		containerID := ctx.Args().Get(0)

		var commandArr []string
		commandArr = append(commandArr, ctx.Args().Tail()...)

		execConatiner(containerID, commandArr)

		return nil
	},
}
View Source
var InitCommand = cli.Command{
	Name:  "init",
	Usage: "Init container process run user's process in container. Do not call it outside.",
	Flags: nil,

	Action: func(ctx *cli.Context) error {
		logrus.Infof("init come on")
		err := container.RunContainerInitProcess()
		return err
	},
}

InitCommand .

View Source
var LogCommand = cli.Command{
	Name:  "log",
	Usage: "print logs of a container",
	Action: func(ctx *cli.Context) error {
		if len(ctx.Args()) < 1 {
			return fmt.Errorf("please input your container id :)")
		}

		containerID := ctx.Args().Get(0)
		logContainer(containerID)
		return nil
	},
}
View Source
var NetworkCommand = cli.Command{
	Name:  "network",
	Usage: "container network commands",
	Subcommands: []cli.Command{
		createCommand,
		listCommand,
		removeCommand,
	},
}
View Source
var PsCommand = cli.Command{
	Name:  "ps",
	Usage: "list all the container",
	Action: func(ctx *cli.Context) error {
		ListContainers()
		return nil
	},
}
View Source
var RemoveCommand = cli.Command{
	Name:  "rm",
	Usage: "remove a container",
	Action: func(ctx *cli.Context) error {
		if len(ctx.Args()) < 1 {
			return errors.New("missing containerID")
		}

		containerID := ctx.Args().Get(0)
		return removeContainer(containerID)
	},
}
View Source
var RunCommand = cli.Command{
	Name: "run",
	Usage: `Create a container with namespace and cgroups limit
			 ddocker run -it [command]`,
	Flags: []cli.Flag{

		cli.BoolFlag{
			Name:  "it",
			Usage: "enable tty",
		},

		cli.BoolFlag{
			Name:  "d",
			Usage: "detach container",
		},
		cli.StringFlag{
			Name:  "mm",
			Usage: "memory limit",
		},
		cli.StringFlag{
			Name:  "cpushare",
			Usage: "cpushare limit",
		},
		cli.StringFlag{
			Name:  "cpuset",
			Usage: "cpuset limit",
		},
		cli.StringFlag{
			Name:  "v",
			Usage: "volume",
		},
		cli.StringFlag{
			Name:  "name",
			Usage: "container name",
		},
		cli.StringSliceFlag{
			Name:  "e",
			Usage: "set environment",
		},
		cli.StringFlag{
			Name:  "net",
			Usage: "container network",
		},
		cli.StringSliceFlag{
			Name:  "p",
			Usage: "port mapping",
		},
	},

	Action: func(ctx *cli.Context) error {
		if len(ctx.Args()) < 1 {
			return errors.New("missing container command")
		}

		var commands []string
		for _, arg := range ctx.Args() {
			fmt.Println(arg)
			commands = append(commands, arg)
		}

		tty := ctx.Bool("it")
		detach := ctx.Bool("d")
		if tty && detach {
			return errors.New("-it and -d parameter can not both provider")
		}

		resConf := &subsystems.ResourceConfig{
			MemoryLimit: ctx.String("mm"),
			CPUSet:      ctx.String("cpuset"),
			CPUShare:    ctx.String("cpushare"),
		}

		containerName := ctx.String("name")
		volumes := ctx.String("v")
		imageName := commands[0]
		commands = commands[1:]

		logrus.Infof("create tty[%v] name[%v]", tty, containerName)

		env := ctx.StringSlice("e")
		logrus.Infof("create env [%v]", env)

		network := ctx.String("net")
		logrus.Infof("create net [%v]", network)

		portMapping := ctx.StringSlice("p")
		logrus.Infof("create portMapping [%v]", portMapping)

		run(tty, commands, resConf, containerName, volumes, imageName, env, network, portMapping)
		return nil
	},
}

RunCommand .

View Source
var StopCommand = cli.Command{
	Name:  "stop",
	Usage: "stop a container",
	Action: func(ctx *cli.Context) error {
		if len(ctx.Args()) < 1 {
			return errors.New("missing containerID")
		}

		containerID := ctx.Args().Get(0)
		return stopContainer(containerID)
	},
}

Functions

func GetContainerInfo

func GetContainerInfo(contianerID string) *container.ContainerInfo

func GetContainerPID

func GetContainerPID(contianerID string) string

func ListContainers

func ListContainers()

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL