Examples or documentation on UpdateServiceAsync
- Dominant language
- C#
- Stars
- 2.4k
- Forks
- 416
- PR merge metrics
- No merged PRs in 30d
Description
I'm looking for examples or documentation on how to update service using this SDK. I have a successfully connected client, can list containers and services, and kill containers. But when I'm trying to use client.Swarm.UpdateServiceAsync I just can't seem to make it work.
My goal (for now) is to toggle a service between 0 or 1 replicas with a single button press from a custom UI.
I've tried copying the spec from the original service retrieved with the ListServicesAsync method.
```
private async Task Toggle(SwarmService service)
{
var parameters = new ServiceUpdateParameters();
parameters.Service = service.Spec;
parameters.Service.Mode.Replicated.Replicas = (ulong?)(service.Spec.Mode.Replicated.Replicas.GetValueOrDefault(0) == 0 ? 1 : 0);
await client.Swarm.UpdateServiceAsync(service.ID, parameters);
}
```
which yields the error
```
Docker.DotNet.DockerApiException: 'Docker API responded with status code=InternalServerError, response={"message":"rpc error: code = Unknown desc = update out of sequence"}'
```
I've also tried with making a blank spec, containing only the change that I want to make
```
private async Task Toggle(SwarmService service)
{
var parameters = new ServiceUpdateParameters();
parameters.Service = new ServiceSpec();
parameters.Service.Mode = new ServiceMode();
parameters.Service.Mode.Replicated = new ReplicatedService();
parameters.Service.Mode.Replicated.Replicas = (ulong?)(service.Spec.Mode.Replicated.Replicas.GetValueOrDefault(0) == 0 ? 1 : 0);
await client.Swarm.UpdateServiceAsync(service.ID, parameters);
}
```
which yields the errorr
```
Docker.DotNet.DockerApiException: 'Docker API responded with status code=BadRequest, response={"message":"mismatched Runtime and *Spec fields"}'
```
I've also tried various other mixes, but all led to one of the errors mentioned above.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.