Changing amount of replicas for swarm produces more changes than expected
See original GitHub issueGeneral Information
docker-java version: 3.1.0-SNAPSHOT
docker-compose version: docker-compose version 1.17.1, build 6d101fb
docker version: Docker version 17.09.0-ce, build afdb6d4
Problem
Iterating over my services received via DockerClient#listServicesCmd()
and then scaling them up with
/* some example code to explain - variable "service" is a service from the iteration and "dockerClient" is an instance of DockerClient */
ServiceSpec serviceSpec = service.getSpec();
ServiceModeConfig serviceModeConfig = service.getSpec().getMode();
ServiceReplicatedModeOptions serviceReplicatedModeOptions = service.getSpec().getMode().getReplicated().withReplicas(2);
serviceModeConfig = serviceModeConfig.withReplicated(serviceReplicatedModeOptions);
serviceSpec = serviceSpec.withMode(serviceModeConfig);
dockerClient.updateServiceCmd(service.getId(), serviceSpec).withVersion(service.getVersion().getIndex()).exec();
produces an interesting diff:
"Spec": {
"Name": "<NAME>",
"Labels": {
"com.docker.stack.image": "<IMAGE_NAMESPACE>/<IMAGE_NAME>",
"com.docker.stack.namespace": "<NAMESPACE>"
},
"TaskTemplate": {
"ContainerSpec": {
"Image": "<IMAGE_NAMESPACE>/<IMAGE_NAME>:latest",
"Labels": {
"com.docker.stack.namespace": "<NAMESPACE>"
},
"Env": [],
- "Privileges": {
- "CredentialSpec": null,
- "SELinuxContext": null
- },
"TTY": true,
- "OpenStdin": true,
- "StopGracePeriod": 60000000000
+ "StopGracePeriod": 10000000000,
+ "DNSConfig": {}
},
"Resources": {
"Limits": {
"MemoryBytes": 536870912
}
},
"RestartPolicy": {
"Condition": "none",
"Delay": 5000000000,
"MaxAttempts": 3,
"Window": 20000000000
},
"Placement": {},
- "Networks": [{
- "Target": "fzmfcwseizy9l7xtbbeq8fuh8",
- "Aliases": [
- "hub"
- ]
- }],
"ForceUpdate": 0,
"Runtime": "container"
},
"Mode": {
"Replicated": {
- "Replicas": 0
+ "Replicas": 2
}
+ },
+ "UpdateConfig": {
+ "Parallelism": 1,
+ "FailureAction": "pause",
+ "Monitor": 5000000000,
+ "MaxFailureRatio": 0,
+ "Order": "stop-first"
+ },
+ "RollbackConfig": {
+ "Parallelism": 1,
+ "FailureAction": "pause",
+ "Monitor": 5000000000,
+ "MaxFailureRatio": 0,
+ "Order": "stop-first"
},
"EndpointSpec": {
"Mode": "vip"
}
}
- "Endpoint": {
- "Spec": {
- "Mode": "vip"
- }
- }
I thought, just the amount of replicas ("Replicas": 0
to "Replicas": 2
) would change. Why are there so many other changes? For me, especially the missing network part is a problem. Maybe someone has an idea why this is happening or has proper working code for scaling the amount of a service’s replicas.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Deploy services to a swarm - Docker Documentation
Replicated or global services For replicated services, you specify the number of replica tasks for the swarm manager to schedule onto available nodes....
Read more >How to Scale Docker Swarm Horizontally in Production | Better ...
Learn how to horizontally scale in/out an existing Docker Swarm cluster, ... the same as running a service update to change the number...
Read more >Scheduling Services on a Docker Swarm Mode Cluster
Services in Swarm Mode are an abstraction of a workload, and comprise of one or more tasks, which are implemented as individual containers....
Read more >Docker swarm in global mode makes too many replicas of ...
This behavior causes that almost everytime I change any other service, the problem with replicas I described above appears.
Read more >Understanding Basic Kubernetes Concepts I - Giant Swarm
As indicated above the replica set ensures a specific number of replicas are running. By modifying the number of replicas in the set's ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually it is not documented https://docs.docker.com/engine/api/v1.30/#operation/ServiceUpdate you has to decipher it yourself.
Edit /etc/docker/daemon.json to add
"debug": true
, then update service using docker cli, and monitor /var/log/message for the request body, sample I trieddocker service update --replicate 3 worker
and got below request@sebastianbinder I encountered the same question as you working with the docker API. Do I have to specify everything as upon service creation or is it possible updating only a single thing of the service, for example the name?