Skip to content

docker stack

StackCLI

deploy

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

Deploys a stack.

PARAMETER DESCRIPTION
name

The name of the stack to deploy. Mandatory.

TYPE: str

compose_files

One or more docker-compose files. If there are more than one, they will be fused together.

TYPE: Union[ValidPath, List[ValidPath]] DEFAULT: []

orchestrator

The orchestrator to use, `"swarm" or "kubernetes" or "all".

TYPE: Optional[str] DEFAULT: None

prune

Prune services that are no longer referenced

TYPE: bool DEFAULT: False

resolve_image

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.

TYPE: str DEFAULT: 'always'

with_registry_auth

Send registry authentication details to Swarm agents. Required if you need to run docker login to pull the docker images in your stack.

TYPE: bool DEFAULT: False

env_files

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.

TYPE: List[ValidPath] DEFAULT: []

variables

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.

TYPE: Dict[str, str] DEFAULT: {}

Returns

A `python_on_whales.Stack` object.

list

list()

Returns a list of python_on_whales.Stack

Returns

A `List[python_on_whales.Stack]`.

ps

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
PARAMETER DESCRIPTION
x

A stack . It can be name or a python_on_whales.Stack object.

TYPE: ValidStack

Returns

`List[python_on_whales.Task]`

remove

remove(x)

Removes one or more stacks.

PARAMETER DESCRIPTION
x

One or more stacks, empty list means nothing will be done.

TYPE: Union[ValidStack, List[ValidStack]]

services

services(stack)

List the services present in the stack.

PARAMETER DESCRIPTION
stack

A docker stack or the name of a stack.

TYPE: ValidStack

Returns

A `List[python_on_whales.Stack]`