deploy

docker.stack.deploy(
    name,
    compose_files=[],
    orchestrator=None,
    prune=False,
    resolve_image="always",
    with_registry_auth=False,
    env_files=[],
    variables={},
)

Deploys a stack.

Arguments

  • name str: The name of the stack to deploy. Mandatory.
  • compose_files Union[str, pathlib.Path, List[Union[str, pathlib.Path]]]: One or more docker-compose files. If there are more than one, they will be fused together.
  • orchestrator Optional[str]: The orchestrator to use, `"swarm" or "kubernetes" or "all".
  • prune bool: Prune services that are no longer referenced
  • resolve_image str: Query the registry to resolve image digest and supported platforms "always"|"changed"|"never" (default "always"). Note that if the registry cannot be queried when using "always", it's going to try to use images present locally on the nodes.
  • with_registry_auth bool: Send registry authentication details to Swarm agents. Required if you need to run docker login to pull the docker images in your stack.
  • env_files List[Union[str, pathlib.Path]]: Similar to .env files in docker-compose. Loads variables from .env files. If both env_files and variables are used, variables have priority. This behavior is similar to the one you would experience with compose.
  • variables Dict[str, str]: A dict dictating by what to replace the variables declared in the docker-compose files. In the docker CLI, you would use environment variables for this.

Returns

A python_on_whales.Stack object.


list

docker.stack.list()

Returns a list of python_on_whales.Stack

Returns

A List[python_on_whales.Stack].


ps

docker.stack.ps(x)

Returns the list of swarm tasks in this stack.

from python_on_whales import docker

tasks = docker.stack.ps("my-stack")
print(tasks[0].desired_state)
# running

Arguments

  • x Union[str, python_on_whales.Stack]: A stack . It can be name or a python_on_whales.Stack object.

Returns

List[python_on_whales.Task]


remove

docker.stack.remove(x)

Removes one or more stacks.

Arguments

  • x Union[str, python_on_whales.Stack, List[Union[str, python_on_whales.Stack]]]: One or more stacks, empty list means nothing will be done.

services

docker.stack.services(stack)

List the services present in the stack.

Arguments

  • stack Union[str, python_on_whales.Stack]: A docker stack or the name of a stack.

Returns

A List[python_on_whales.Stack]