Services¶
- class aiodocker.services.DockerServices(docker)[source]¶
- async create(task_template: Mapping[str, Any], *, name: str | None = None, labels: Mapping[str, str] | None = None, mode: Mapping | None = None, update_config: Mapping | None = None, rollback_config: Mapping | None = None, networks: List[Any] | None = None, endpoint_spec: Mapping | None = None, auth: MutableMapping | str | bytes | None = None, registry: str | None = None) Mapping[str, Any][source]¶
Create a service
- Parameters:
task_template – user modifiable task configuration
name – name of the service
labels – user-defined key/value metadata
mode – scheduling mode for the service
update_config – update strategy of the service
rollback_config – rollback strategy of the service
networks – array of network names/IDs to attach the service to
endpoint_spec – ports to expose
auth – authentication information, can be a string, dict or bytes
registry – used when auth is specified, it provides domain/IP of the registry without a protocol
- Returns:
a dict with info of the created service
- async delete(service_id: str) bool[source]¶
Remove a service
- Parameters:
service_id – ID or name of the service
- Returns:
True if successful
- async inspect(service_id: str) Mapping[str, Any][source]¶
Inspect a service
- Parameters:
service_id – ID or name of the service
- Returns:
a dict with info about a service
- async list(*, filters: Mapping[str, str | Sequence[str]] | None = None) list[Mapping][source]¶
Return a list of services
- Parameters:
filters – a dict with a list of filters
- Available filters:
id=<service id> label=<service label> mode=[“replicated”|”global”] name=<service name>
- logs(service_id: str, *, details: bool = False, follow: bool = False, stdout: bool = False, stderr: bool = False, since: int = 0, timestamps: bool = False, is_tty: bool = False, tail: str = 'all') str | AsyncIterator[str][source]¶
Retrieve logs of the given service
- Parameters:
details – show service context and extra details provided to logs
follow – return the logs as a stream.
stdout – return logs from stdout
stderr – return logs from stderr
since – return logs since this time, as a UNIX timestamp
timestamps – add timestamps to every log line
is_tty – the service has a pseudo-TTY allocated
tail – only return this number of log lines from the end of the logs, specify as an integer or all to output all log lines.
- async update(service_id: str, version: str, *, image: str | None = None, rollback: bool = False) bool[source]¶
Update a service. If rollback is True image will be ignored.
- Parameters:
service_id – ID or name of the service.
version – Version of the service that you want to update.
rollback – Rollback the service to the previous service spec.
- Returns:
True if successful.
Example¶
Create a service¶
import asyncio
import aiodocker
async def create_service():
docker = aiodocker.Docker()
task_template = {
"ContainerSpec": {
"Image": "redis",
},
}
service = await docker.services.create(
task_template=task_template,
name="my_service"
)
print(service)
await docker.close()
if __name__ == "__main__":
asyncio.run(create_service())