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
task_template (
Mapping
[str
,Any
]) – user modifiable task configurationlabels (
Optional
[Mapping
[str
,str
]]) – user-defined key/value metadataupdate_config (
Optional
[Mapping
]) – update strategy of the servicerollback_config (
Optional
[Mapping
]) – rollback strategy of the servicenetworks (
Optional
[List
]) – array of network names/IDs to attach the service toauth (
Union
[MutableMapping
,str
,bytes
,None
]) – authentication information, can be a string, dict or bytesregistry (
Optional
[str
]) – used when auth is specified, it provides domain/IP of the registry without a protocol
- Return type
- Returns
a dict with info of the created service
- coroutine list(self, *, filters=None)[source]¶
Return a list of services
- Available filters:
id=<service id> label=<service label> mode=[“replicated”|”global”] name=<service name>
- 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 logsfollow (
bool
) – return the logs as a stream.stdout (
bool
) – return logs from stdoutstderr (
bool
) – return logs from stderrsince (
int
) – return logs since this time, as a UNIX timestamptimestamps (
bool
) – add timestamps to every log lineis_tty (
bool
) – the service has a pseudo-TTY allocatedtail (
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
]]