Services¶
Manage services on a swarm. For more information about services, see the Engine documentation.
Before you can use any of these methods, you first need to join or initialize a swarm.
Methods available on client.services:
Service objects¶
- class Service¶
A service.
- id¶
The ID of the object.
- short_id¶
The ID of the object, truncated to 12 characters.
- name¶
The service’s name.
- version¶
The version number of the service. If this is not the same as the server, the
update()function will not work and you will need to callreload()before calling it again.
- attrs¶
The raw representation of this object from the server.
- force_update()¶
Force update the service even if no changes require it.
- Returns:
Trueif successful.- Return type:
bool
- logs(**kwargs)¶
Get log stream for the service. Note: This method works only for services with the
json-fileorjournaldlogging drivers.- Parameters:
details (bool) – Show extra details provided to logs. Default:
Falsefollow (bool) – Keep connection open to read logs as they are sent by the Engine. Default:
Falsestdout (bool) – Return logs from
stdout. Default:Falsestderr (bool) – Return logs from
stderr. Default:Falsesince (int) – UNIX timestamp for the logs staring point. Default: 0
timestamps (bool) – Add timestamps to every log line.
tail (string or int) – Number of log lines to be returned, counting from the current end of the logs. Specify an integer or
'all'to output all log lines. Default:all
- Returns:
Logs for the service.
- Return type:
generator
- reload()¶
Load this object from the server again and update
attrswith the new data.
- remove()¶
Stop and remove the service.
- Raises:
docker.errors.APIError – If the server returns an error.
- scale(replicas)¶
Scale service container.
- Parameters:
replicas (int) – The number of containers that should be running.
- Returns:
Trueif successful.- Return type:
bool
- tasks(filters=None)¶
List the tasks in this service.
- Parameters:
filters (dict) – A map of filters to process on the tasks list. Valid filters:
id,name,node,label, anddesired-state.- Returns:
List of task dictionaries.
- Return type:
list- Raises:
docker.errors.APIError – If the server returns an error.