newUpdateCommand creates a new cobra.Command for "docker container update".
(dockerCLI command.Cli)
| 38 | |
| 39 | // newUpdateCommand creates a new cobra.Command for "docker container update". |
| 40 | func newUpdateCommand(dockerCLI command.Cli) *cobra.Command { |
| 41 | var options updateOptions |
| 42 | |
| 43 | cmd := &cobra.Command{ |
| 44 | Use: "update [OPTIONS] CONTAINER [CONTAINER...]", |
| 45 | Short: "Update configuration of one or more containers", |
| 46 | Args: cli.RequiresMinArgs(1), |
| 47 | RunE: func(cmd *cobra.Command, args []string) error { |
| 48 | options.containers = args |
| 49 | options.nFlag = cmd.Flags().NFlag() |
| 50 | return runUpdate(cmd.Context(), dockerCLI, &options) |
| 51 | }, |
| 52 | Annotations: map[string]string{ |
| 53 | "aliases": "docker container update, docker update", |
| 54 | }, |
| 55 | ValidArgsFunction: completion.ContainerNames(dockerCLI, true), |
| 56 | DisableFlagsInUseLine: true, |
| 57 | } |
| 58 | |
| 59 | flags := cmd.Flags() |
| 60 | flags.Uint16Var(&options.blkioWeight, "blkio-weight", 0, `Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)`) |
| 61 | flags.Int64Var(&options.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period") |
| 62 | flags.Int64Var(&options.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota") |
| 63 | flags.Int64Var(&options.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds") |
| 64 | _ = flags.SetAnnotation("cpu-rt-period", "version", []string{"1.25"}) |
| 65 | flags.Int64Var(&options.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds") |
| 66 | _ = flags.SetAnnotation("cpu-rt-runtime", "version", []string{"1.25"}) |
| 67 | flags.StringVar(&options.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)") |
| 68 | flags.StringVar(&options.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)") |
| 69 | flags.Int64VarP(&options.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)") |
| 70 | flags.VarP(&options.memory, "memory", "m", "Memory limit") |
| 71 | flags.Var(&options.memoryReservation, "memory-reservation", "Memory soft limit") |
| 72 | flags.Var(&options.memorySwap, "memory-swap", `Swap limit equal to memory plus swap: -1 to enable unlimited swap`) |
| 73 | |
| 74 | flags.StringVar(&options.restartPolicy, "restart", "", "Restart policy to apply when a container exits") |
| 75 | flags.Int64Var(&options.pidsLimit, "pids-limit", 0, `Tune container pids limit (set -1 for unlimited)`) |
| 76 | _ = flags.SetAnnotation("pids-limit", "version", []string{"1.40"}) |
| 77 | |
| 78 | flags.Var(&options.cpus, "cpus", "Number of CPUs") |
| 79 | _ = flags.SetAnnotation("cpus", "version", []string{"1.29"}) |
| 80 | |
| 81 | _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) |
| 82 | |
| 83 | // TODO(thaJeztah): remove in next release (v30.0, or v29.x) |
| 84 | var stub opts.MemBytes |
| 85 | flags.Var(&stub, "kernel-memory", "Kernel memory limit (deprecated)") |
| 86 | _ = flags.MarkDeprecated("kernel-memory", "and no longer supported by the kernel") |
| 87 | |
| 88 | return cmd |
| 89 | } |
| 90 | |
| 91 | func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOptions) error { |
| 92 | var err error |
no test coverage detected
searching dependent graphs…