Hi,
I'm trying to scale a docker swarm service using python script. I can't find a way to do it from docker-py documentation. Is it possible or not? if possible, How? if not, How else should I approach this problem(scaling through script)?
Thanks in advance
It's kind of rough right now and it might change in a future version of docker-py, but the way to do it right now would be to call update_service with mode={'Replicated': {'Replicas': n}}.
Thanks.
Hi All I am trying to Scale up the no of containers in my service but I am getting these errors. Can someone help me what I am missing in the update command?
service.update(mode=replica_mode)
Traceback (most recent call last):
File "", line 1, in
File "/home/qraza/.local/lib/python2.7/site-packages/docker/models/services.py", line 77, in update
*create_kwargs
File "/home/qraza/.local/lib/python2.7/site-packages/docker/utils/decorators.py", line 34, in wrapper
return f(self, *args, *kwargs)
File "/home/qraza/.local/lib/python2.7/site-packages/docker/utils/decorators.py", line 19, in wrapped
return f(self, resource_id, args, *kwargs)
File "/home/qraza/.local/lib/python2.7/site-packages/docker/api/service.py", line 350, in update_service
self._raise_for_status(resp)
File "/home/qraza/.local/lib/python2.7/site-packages/docker/api/client.py", line 222, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/home/qraza/.local/lib/python2.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("rpc error: code = 12 desc = renaming services is not supported")
Let me also paste my code here
import docker
client=docker.from_env()
total_containers=5 #
replica_mode = docker.types.ServiceMode('replicated', replicas=total_containers)
testservice=client.services.create(image='alpine',command='ping docker.com',name='testservicev6',mode=replica_mode)
total_containers=10
replica_mode = docker.types.ServiceMode('replicated', replicas=total_containers)
testservice.update(mode=replica_mode)
see https://github.com/moby/moby/issues/34116 and #1686
Most helpful comment
It's kind of rough right now and it might change in a future version of
docker-py, but the way to do it right now would be to callupdate_servicewithmode={'Replicated': {'Replicas': n}}.