func runServiceScale(dockerCli *client.DockerCli, serviceID string, scale string) error { client := dockerCli.Client() ctx := context.Background() service, err := client.ServiceInspect(ctx, serviceID) if err != nil { return err } serviceMode := &service.Spec.Mode if serviceMode.Replicated == nil { return fmt.Errorf("scale can only be used with replicated mode") } uintScale, err := strconv.ParseUint(scale, 10, 64) if err != nil { return fmt.Errorf("invalid replicas value %s: %s", scale, err.Error()) } serviceMode.Replicated.Replicas = &uintScale err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec) if err != nil { return err } fmt.Fprintf(dockerCli.Out(), "%s scaled to %s\n", serviceID, scale) return nil }
func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID string) error { client := dockerCli.Client() ctx := context.Background() service, err := client.ServiceInspect(ctx, serviceID) if err != nil { return err } err = mergeService(&service.Spec, flags) if err != nil { return err } err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec) if err != nil { return err } fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID) return nil }