Docker-py: how to scale a service

Created on 20 Oct 2016  路  5Comments  路  Source: docker/docker-py

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

kinquestion

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 call update_service with mode={'Replicated': {'Replicas': n}}.

All 5 comments

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}}.

1260

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

Start the docker client

client=docker.from_env()

As we already Created the Swarm cluster so need to initialize the cluster here

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)

Was this page helpful?
0 / 5 - 0 ratings