docker service
ServiceCLI
create
create(image, command, cap_add=[], cap_drop=[], constraints=[], detach=False, dns=[], dns_options=[], dns_search=[], endpoint_mode=None, entrypoint=None, envs={}, env_files=[], generic_resources=[], groups=[], healthcheck=True, health_cmd=None, health_interval=None, health_retries=None, health_start_period=None, health_timeout=None, hosts={}, hostname=None, init=False, isolation=None, labels={}, limit_cpu=None, limit_memory=None, limit_pids=None, log_driver=None, network=None, restart_condition=None, restart_max_attempts=None, secrets=[], mounts=[])
Creates a Docker swarm service.
Consider using 'docker stack deploy' instead as it's idempotent and easier to read for complex applications. docker stack deploy is basically docker compose for swarm clusters.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to use as the base for the service.
TYPE:
|
command |
The command to execute in the container(s).
TYPE:
|
exists
exists(x)
Verify that a service exists.
It's just calling docker.service.inspect(...)
and verifies that it doesn't throw
a python_on_whales.exceptions.NoSuchService
.
Returns
A `bool`
inspect
inspect(x)
Returns one or a list of python_on_whales.Service
object(s).
Raises
`python_on_whales.exceptions.NoSuchService` if one of the services
doesn't exists.
list
list(filters={})
Returns the list of services
PARAMETER | DESCRIPTION |
---|---|
filters |
If you want to filter the results based on a given condition.
For example,
TYPE:
|
Returns
A `List[python_on_whales.Services]`
logs
logs(service, details=False, since=None, tail=None, timestamps=False, follow=False, raw=False, task_ids=True, resolve=True, truncate=True, stream=False)
Returns the logs of a service as a string or an iterator.
PARAMETER | DESCRIPTION |
---|---|
service |
The service to get the logs of
TYPE:
|
details |
Show extra details provided to logs
TYPE:
|
since |
Use a datetime or timedelta to specify the lower date limit for the logs.
TYPE:
|
tail |
Number of lines to show from the end of the logs (default all)
TYPE:
|
timestamps |
Put timestamps next to lines.
TYPE:
|
follow |
If
TYPE:
|
stream |
Similar to the
TYPE:
|
Returns
`str` if `stream=False` (the default), `Iterable[Tuple[str, bytes]]`
if `stream=True`.
Raises
`python_on_whales.exceptions.NoSuchService` if the service does not exists.
ps
ps(x)
Returns the list of swarm tasks associated with this service.
You can pass multiple services at once at this function.
from python_on_whales import docker
tasks = docker.service.ps("my-service-name")
print(tasks[0].desired_state)
# running
PARAMETER | DESCRIPTION |
---|---|
x |
One or more services (can be id, name or
TYPE:
|
Returns
`List[python_on_whales.Task]`
Raises
`python_on_whales.exceptions.NoSuchService` if one of the services
doesn't exist.
remove
remove(services)
Removes a service
PARAMETER | DESCRIPTION |
---|---|
services |
One or a list of services to remove.
TYPE:
|
Raises
`python_on_whales.exceptions.NoSuchService` if one of the services
doesn't exist.
rollback
rollback()
Not yet implemented
scale
scale(new_scales, detach=False)
Scale one or more services.
PARAMETER | DESCRIPTION |
---|---|
new_scales |
Mapping between services and the desired scales. For example
you can provide
TYPE:
|
detach |
If True, does not wait for the services to converge and return immediately.
TYPE:
|
Raises
`python_on_whales.exceptions.NoSuchService` if one of the services
doesn't exists.
update
update(service, detach=False, force=False, image=None, with_registry_authentication=False, quiet=False, replicas=None)
Update a service
More options coming soon
PARAMETER | DESCRIPTION |
---|---|
service |
The service to update
TYPE:
|
detach |
Exit immediately instead of waiting for the service to converge
TYPE:
|
force |
Force update even if no changes require it
TYPE:
|
image |
Service image tag
TYPE:
|
with_registry_authentication |
Send registry authentication details to swarm agents
TYPE:
|
Raises
`python_on_whales.exceptions.NoSuchService` if the service doesn't exists.