CLI for deploying and managing Docker stacks.
Project description
Docker Stack CLI Utility
A command-line tool for advanced Docker Swarm stack deployments on plain Docker daemons. docker-stack extends vanilla docker stack deploy with generated secrets, templated configs, versioned stack state, safer rollbacks, and better day-to-day stack workflows.
Installation
Install or upgrade docker-stack with:
pip install docker-stack --upgrade --break-system-packages
Quick Start
Plain Docker Daemon
If you already have a Docker Swarm daemon or Docker context, you can use the advanced stack features directly against it.
Typical daemon-only workflow:
docker-stack deploy my-stack docker-compose.yml
docker-stack ls
docker-stack versions my-stack
docker-stack cat my-stack
docker-stack checkout my-stack v2
docker-stack node ls
What this gives you on a raw Docker daemon:
- richer secret and config handling in Compose
- generated secrets without external scripts
- template expansion from env vars and files
- versioned stack config history
- stack version inspection and checkout
- raw daemon compatibility without extra infrastructure
GitHub Actions
If you want to use docker-stack directly in a workflow, install the package explicitly:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v6
with:
python-version: '3.x'
- run: python3 -m pip install --upgrade docker-stack
- run: docker-stack deploy my-stack docker-compose.yml
Core Capabilities
-
Advanced Deployments on Plain Docker Daemons:
docker-stackworks directly against a raw Docker daemon and adds capabilities that standarddocker stack deploydoes not provide out of the box:- generated secrets
- inline configs and secrets
- template rendering from environment variables and files
- versioned config and secret history
- version lookup, checkout, and rollback-oriented workflows
- more ergonomic stack and node inspection output
-
Docker Stack Versioning and Config Backup for Rollback: The utility automatically versions your Docker configs and secrets, allowing for easy tracking of changes and seamless rollbacks to previous states. This provides a safety net for your deployments, ensuring you can always revert to a stable configuration.
Why Use It?
Vanilla Docker Stack deployments can sometimes lack the flexibility needed for dynamic environments or robust secret management. This utility bridges those gaps by:
- Automating Secret Management: No more manual secret generation or complex external scripts.
- Simplifying Configuration: Define configs and secrets directly in your compose files or use templates.
- Enhancing Security: Generate strong, random secrets on the fly.
- Enabling Rollbacks: Versioning ensures you can always revert to a known good state.
- Improving Raw Daemon Workflows: Works directly with a plain Docker Swarm daemon.
Advanced Compose Features
-
Docker Config and Secret Management with Extended Options: This utility significantly extends Docker's native config and secret management by introducing
x-prefixed directives in yourdocker-compose.ymlfiles. These directives allow for dynamic content generation, templating, and file inclusion, making your deployments more flexible and secure.x-content: Inline Content for Configs and SecretsAllows you to define the content of a Docker config or secret directly within your
docker-compose.yml.secrets: my_inline_secret: x-content: "This is my secret content defined inline." configs: my_inline_config: x-content: | key=value another_key=another_value
x-template: Environment Variable TemplatingEnables the use of environment variables within your config or secret content, which are substituted at deployment time.
secrets: my_templated_secret: x-template: "I can create composite secret with template. ${API_KEY_NAME}:${MY_API_KEY}"
x-template-file: External Template FilesReference an external file whose content will be treated as a template and processed with environment variables.
configs: my_config_from_template_file: x-template-file: "./templates/my_config.tpl"
(Content of
./templates/my_config.tplmight be:DB_HOST=${DATABASE_HOST})x-generate: Dynamic Secret Generation (Secrets Only)This powerful feature allows you to automatically generate random secrets based on specified criteria, eliminating the need to manually create and manage them. This is particularly useful for passwords, API keys, and other sensitive data.
Supported
x-generateforms:trueGenerate a secret with default options.- integer Generate a secret with the requested length.
- object Generate a secret with explicit generation flags.
Supported object flags:
lengthExact secret length.numbersInclude digits0-9.specialInclude special characters.uppercaseInclude uppercase lettersA-Z.
Behavior notes:
-
Generated values are created at deploy time.
-
Generated secrets are versioned like other managed secrets.
-
Newly generated values can be shown after deploy when
--show-generatedis enabled. -
x-generateis for secrets only; configs should usex-content,x-template, orx-template-file. -
Simple Generation (12-20 characters, default options):
secrets: my_simple_generated_secret: x-generate: true
-
Specify Length:
secrets: my_fixed_length_secret: x-generate: 30 # Generates a 30-character secret
-
Custom Generation Options: You can provide a dictionary to fine-tune the generation process:
length: (integer, default: 12-20 random) Exact length of the secret.numbers: (boolean, default:true) Include numbers (0-9).special: (boolean, default:true) Include special characters (!@#$%^&*...).uppercase: (boolean, default:true) Include uppercase letters (A-Z).
secrets: my_complex_generated_secret: x-generate: length: 25 numbers: false special: true uppercase: true my_alphanumeric_secret: x-generate: length: 15 numbers: true special: false uppercase: false
-
Database Password Style Secret: Generates a strong password with uppercase letters, lowercase letters, numbers, and special characters.
secrets: db_password: x-generate: length: 32 numbers: true special: false uppercase: true
-
Application Token Without Special Characters: Useful when the target application rejects punctuation in credentials or tokens.
secrets: app_token: x-generate: length: 40 numbers: true special: false uppercase: true
-
Lowercase Alphanumeric Secret: Useful for systems that want URL-safe or copy-friendly generated values.
secrets: compact_secret: x-generate: length: 24 numbers: true special: false uppercase: false
Development
Install runtime and test dependencies with either:
python3 -m pip install -r requirements-dev.txt
or:
python3 -m pip install -e '.[dev]'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docker_stack-2.0.3.tar.gz.
File metadata
- Download URL: docker_stack-2.0.3.tar.gz
- Upload date:
- Size: 50.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b50cb7c9612745492d2a30c06e60f0a9eec2f9d959ea0e864b22593426f9bdd
|
|
| MD5 |
1cca41060309a295a8a8c15d4c435762
|
|
| BLAKE2b-256 |
67124b2286f96fa290a8a98935451b28fda421ffa63f260aed25d50326eeae25
|
File details
Details for the file docker_stack-2.0.3-py3-none-any.whl.
File metadata
- Download URL: docker_stack-2.0.3-py3-none-any.whl
- Upload date:
- Size: 42.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ea30c8c77a72a9a5d2d94a3621cecafdfc43c3dde1cddd9c7dba0f5a234628
|
|
| MD5 |
8fbb506d61dabfdd985fdd03e36786f9
|
|
| BLAKE2b-256 |
4d48f46434f9ac24f38b2c68806f92b9dd4f388f51123b99a1cfc0dd8d9b45fe
|