Example #1
func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
	opts := newServiceOptions()
	var flags *pflag.FlagSet

	cmd := &cobra.Command{
		Use:   "update [OPTIONS] SERVICE",
		Short: "Update a service",
		Args:  cli.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runUpdate(dockerCli, flags, args[0])

	flags = cmd.Flags()
	flags.String("image", "", "Service image tag")
	flags.StringSlice("command", []string{}, "Service command")
	flags.StringSlice("arg", []string{}, "Service command args")
	addServiceFlags(cmd, opts)
	return cmd
Example #2
// AddServiceFlags add all supported service flags to the flagset.
func AddServiceFlags(flags *pflag.FlagSet) {
	flags.String("name", "", "service name")
	flags.StringSlice("label", nil, "service label (key=value)")

	flags.Uint64("replicas", 1, "number of replicas for the service (only works in replicated service mode)")

	flags.String("image", "", "container image")
	flags.StringSlice("command", nil, "override entrypoint")
	flags.StringSlice("args", nil, "container args")
	flags.StringSlice("env", nil, "container env")

	flags.StringSlice("ports", nil, "ports")
	flags.String("network", "", "network name")

	flags.String("memory-reservation", "", "amount of reserved memory (e.g. 512m)")
	flags.String("memory-limit", "", "memory limit (e.g. 512m)")
	flags.String("cpu-reservation", "", "number of CPU cores reserved (e.g. 0.5)")
	flags.String("cpu-limit", "", "CPU cores limit (e.g. 0.5)")

	flags.Uint64("update-parallelism", 0, "task update parallelism (0 = all at once)")
	flags.String("update-delay", "0s", "delay between task updates (0s = none)")

	flags.String("restart-condition", "any", "condition to restart the task (any, failure, none)")
	flags.String("restart-delay", "5s", "delay between task restarts")
	flags.Uint64("restart-max-attempts", 0, "maximum number of restart attempts (0 = unlimited)")
	flags.String("restart-window", "0s", "time window to evaluate restart attempts (0 = unbound)")

	flags.StringSlice("constraint", nil, "Placement constraint (node.labels.key==value)")

	// TODO(stevvooe): Replace these with a more interesting mount flag.
	flags.StringSlice("bind", nil, "define a bind mount")
	flags.StringSlice("volume", nil, "define a volume mount")
	flags.StringSlice("tmpfs", nil, "define a tmpfs mount")

	flags.String("log-driver", "", "specify a log driver")
	flags.StringSlice("log-opt", nil, "log driver options, as key value pairs")