Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ExecCommand = cli.Command{ Name: "exec", Usage: "Run a command in a running container", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "it", Usage: "Interactive mode with pseudo-TTY", }, }, Action: func(ctx *cli.Context) error { if ctx.NArg() < 2 { return errors.New("usage: tinydocker exec [-it] <name> <command> [args...]") } name := ctx.Args().Get(0) args := ctx.Args()[1:] enableTTY := ctx.Bool("it") return container.Exec(name, args, enableTTY) }, }
docker exec [-it] <name> <cmd> [args...]
View Source
var ExecContainerCommand = cli.Command{ Name: "exec-container", Usage: "Internal: execute a command inside target namespaces", Hidden: true, Action: func(ctx *cli.Context) error { return container.ExecContainer(ctx.Args()) }, }
Internal command used after namespace entering to run the actual user command
View Source
var ExportCommand = cli.Command{ Name: "export", Usage: "Package the current running container into a tar file (docker export -o <tarfile> <containerName>)", Flags: []cli.Flag{ &cli.StringFlag{ Name: "o", Usage: "Output file name for the tar file (default is container.tar)", }, }, Action: func(ctx *cli.Context) error { if len(ctx.Args()) == 0 { logger.Error("Usage: tinydocker export [-o <tarfile>] <containerName>") return errors.New("Usage: tinydocker export [-o <tarfile>] <containerName>") } containerName := ctx.Args().Get(0) output := ctx.String("o") if output == "" { output = "container.tar" } if err := image.Export(containerName, output); err != nil { logger.Error("export error: ", err) return err } return nil }, }
docker export imageName
View Source
var InitCommand = cli.Command{ Name: "init", Usage: "Init container process run user's process in container. Do not call it outside", Action: func(ctx *cli.Context) error { logger.Debug("init command args:", ctx.Args()) return container.InitContainerProcess() }, }
View Source
var LogsCommand = cli.Command{ Name: "logs", Usage: "Fetch the logs of a container", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "f", Usage: "Follow log output", }, }, Action: func(ctx *cli.Context) error { containerID := ctx.Args().First() if containerID == "" { return errors.New("container name cannot be empty") } follow := ctx.Bool("f") return container.PrintContainerLogs(containerID, follow) }, }
docker logs
View Source
var NetworkCommand = cli.Command{ Name: "network", Usage: "Manage networks", Subcommands: []cli.Command{ { Name: "create", Usage: "Create a network", Flags: []cli.Flag{ &cli.StringFlag{ Name: "subnet", Usage: "Subnet in CIDR format (e.g., 192.168.243.0/24)", }, &cli.StringFlag{ Name: "driver", Usage: "Network driver (e.g., bridge)", Value: "bridge", }, }, Action: func(ctx *cli.Context) error { name := ctx.Args().First() if name == "" { return errors.New("network name cannot be empty") } subnet := ctx.String("subnet") if subnet == "" { return errors.New("--subnet is required") } driver := ctx.String("driver") return network.CreateNetwork(name, driver, subnet) }, }, { Name: "ls", Usage: "List container network", Action: func(ctx *cli.Context) error { network.ListNetwork() return nil }, }, { Name: "rm", Usage: "Remove one or more networks", Action: func(ctx *cli.Context) error { if ctx.NArg() < 1 { return errors.New("network name is required") } name := ctx.Args().First() if name == "" { return errors.New("network name cannot be empty") } return network.DeleteNetwork(name) }, }, }, }
docker network create --subnet <cidr> --driver <driver> <name> docker network ls docker network rm <name>
View Source
var PsCommand = cli.Command{ Name: "ps", Usage: "List containers", Action: func(ctx *cli.Context) error { return models.PrintContainersInfo() }, }
docker ps
View Source
var RemoveCommand = cli.Command{ Name: "rm", Usage: "Remove one or more containers", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "f", Usage: "Force removal of running container", }, }, Action: func(ctx *cli.Context) error { if ctx.NArg() == 0 { return errors.New("at least one container name or ID must be specified") } name := ctx.Args().Get(0) if len(name) == 0 { return errors.New("container name cannot be empty") } force := ctx.Bool("f") if err := container.Remove(name, force); err != nil { logger.Error("Failed to remove container %s: %v", name, err) return err } return nil }, }
docker rm [-f] <containerNameOrID>
View Source
var RunCommand = cli.Command{ Name: "run", Usage: "Run a command in a new container", Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", Usage: "Assign a name to the container", }, &cli.BoolFlag{ Name: "it", Usage: "Interactive mode with pseudo-TTY", }, &cli.BoolFlag{ Name: "d", Usage: "Run container in detached mode (background)", }, &cli.StringFlag{ Name: "m", Usage: "Memory limit for the container (e.g., 512m, 1g)", }, &cli.StringFlag{ Name: "cpus", Usage: "CPU limit for the container (e.g., 1.5)", }, &cli.StringFlag{ Name: "v", Usage: "Bind mount a volume (host_dir:container_dir)", }, &cli.StringSliceFlag{ Name: "e", Usage: "Set environment variables (e.g., -e KEY=VALUE)", }, &cli.StringFlag{ Name: "net", Usage: "container network", }, &cli.StringSliceFlag{ Name: "p", Usage: "port mapping", }, }, Action: func(ctx *cli.Context) error { args := ctx.Args() logger.Debug("args:", args) if len(args) < 2 { return errors.New("Usage: tinydocker run [OPTIONS] IMAGE COMMAND") } name := ctx.String("name") if name == "" { return errors.New("Container name cannot be empty") } enableTTY := ctx.Bool("it") detach := ctx.Bool("d") if enableTTY && detach { logger.Error("-it and -d cannot be used together") return errors.New("-it and -d cannot be used together") } memoryLimit := ctx.String("m") cpuLimit := ctx.String("cpus") volume := ctx.String("v") envVars := ctx.StringSlice("e") imageName := ctx.Args().Get(0) network := ctx.String("net") portMapping := ctx.StringSlice("p") logger.Debug("enableTTY:", enableTTY, "detach:", detach, "memoryLimit:", memoryLimit, "cpuLimit:", cpuLimit, "volume:", volume, "image:", imageName, "envVars:", envVars) err := container.Run(args[1:], name, enableTTY, detach, memoryLimit, cpuLimit, volume, imageName, envVars, network, portMapping) if err != nil { logger.Error("Run container error:", err) } return err }, }
View Source
var StopCommand = cli.Command{ Name: "stop", Usage: "Stop one or more running containers", Action: func(ctx *cli.Context) error { if ctx.NArg() == 0 { return errors.New("at least one container name or ID must be specified") } name := ctx.Args().Get(0) if len(name) == 0 { return errors.New("container name cannot be empty") } if err := container.Stop(name); err != nil { logger.Error("Failed to stop container %s: %v", name, err) return err } return nil }, }
docker stop <containerNameOrID>
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.