question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing amount of replicas for swarm produces more changes than expected

See original GitHub issue

General 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:closed
  • Created 6 years ago
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
fengxxcommented, Dec 5, 2017

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 tried docker service update --replicate 3 worker and got below request

Dec  5 10:52:55 x dockerd: time="2017-12-05T10:52:55.307104030-05:00" level=debug msg="form data: {\"EndpointSpec\":{\"Mode\":\"vip\"},\"Labels\":{},\"Mode\":{\"Replicated\":{\"Replicas\":3}},
\"Name\":\"worker\",\"TaskTemplate\":{\"ContainerSpec\":{\"DNSConfig\":{},\"Image\":\"busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0\"},\"ForceUpdate\":0,\"Placement\":{\"Platforms\":[{\"Architecture\":\"amd64\",\"OS\":\"linux\"},{\"OS\":\"linux\"},{\"OS\":\"linux\"},{\"OS\":\"linux\"},{\"Architecture\":\"arm64\",\"OS\":\"linux\"},{\"Architecture\":\"386\",\"OS\":\"linux\"},{\"Architecture\":\"ppc64le\",\"OS\":\"linux\"},{\"Architecture\":\"s390x\",\"OS\":\"linux\"}]},\"Resources\":{\"Limits\":{},\"Reservations\":{}},\"Runtime\":\"container\"}}"
0reactions
jaschaiocommented, Apr 19, 2018

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found