Services

Create a service

import asyncio
import aiodocker

docker = aiodocker.Docker()

TaskTemplate = {
    "ContainerSpec": {
        "Image": "redis",
        },
}

async def create_service():
    service = await docker.services.create(
        task_template=TaskTemplate,
        name="my_service"
    )
    await docker.close()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(create_service())
    loop.close()

Reference

DockerServices

class aiodocker.services.DockerServices(docker)[source]
coroutine create(self, task_template, *, name=None, labels=None, mode=None, update_config=None, rollback_config=None, networks=None, endpoint_spec=None, auth=None, registry=None)[source]

Create a service

Parameters
Return type

Mapping[str, Any]

Returns

a dict with info of the created service

coroutine delete(self, service_id)[source]

Remove a service

Parameters

service_id (str) – ID or name of the service

Return type

bool

Returns

True if successful

coroutine inspect(self, service_id)[source]

Inspect a service

Parameters

service_id (str) – ID or name of the service

Return type

Mapping[str, Any]

Returns

a dict with info about a service

coroutine list(self, *, filters=None)[source]

Return a list of services

Parameters

filters (Optional[Mapping]) – a dict with a list of filters

Available filters:

id=<service id> label=<service label> mode=[“replicated”|”global”] name=<service name>

Return type

List[Mapping]

logs(service_id, *, details=False, follow=False, stdout=False, stderr=False, since=0, timestamps=False, is_tty=False, tail='all')[source]

Retrieve logs of the given service

Parameters
  • details (bool) – show service context and extra details provided to logs

  • follow (bool) – return the logs as a stream.

  • stdout (bool) – return logs from stdout

  • stderr (bool) – return logs from stderr

  • since (int) – return logs since this time, as a UNIX timestamp

  • timestamps (bool) – add timestamps to every log line

  • is_tty (bool) – the service has a pseudo-TTY allocated

  • tail (str) – only return this number of log lines from the end of the logs, specify as an integer or all to output all log lines.

Return type

Union[str, AsyncIterator[str]]

coroutine update(self, service_id, version, *, image=None, rollback=False)[source]

Update a service. If rollback is True image will be ignored.

Parameters
  • service_id (str) – ID or name of the service.

  • version (str) – Version of the service that you want to update.

  • rollback (bool) – Rollback the service to the previous service spec.

Return type

bool

Returns

True if successful.