Skip to main content

portmgr

portmgr is a wrapper around docker-compose that allows running typical docker-compose commands recursively. Additionally, it shortens commands to a single letter.

Let's say you have organized your compose files like this, you just add a dckrsub.yml in each parent folder:

docker/
├── dckrsub.yml
├── reverse-proxy/
│   └── docker-compose.yml
├── storage
│   ├── dckrsub.yml
│   ├── nextcloud/
│   │   └── docker-compose.yml
│   └── immich/
│       └── docker-compose.yml
└── scripts

Each dckrsub.yml has a list of subdirectories, which portmgr should decend into. For example, the dckrsub.yml in docker/ might look like this:

- reverse-proxy
- storage

And the dckrsub.yml in docker/storage/ like this:

- nextcloud
- immich

Now, if you run portmgr u in docker/ it will run docker compose up -d in reverse-proxy/, storage/nextcloud/ and storage/immich/.

portmgr starts from the current directory, so when running it in docker/storage/, it will run docker compose only in nextcloud/ and immich/. You can also use it in a directory with a docker-compose.yml as a shortener for docker-compose commands.

One tree for several hosts

To deploy a different set of stacks on each host from the same tree, set PORTMGR_SUB_NAME to a host-specific file name, e.g. PORTMGR_SUB_NAME=dckrsub-web.yml. In every directory portmgr then follows dckrsub-web.yml and dckrsub.yml, if they exist, and runs each stack once. So dckrsub.yml lists what every host runs, and dckrsub-<host>.yml adds what only that host runs. Several names can be given, separated by spaces, commas or semicolons; dckrsub.yml is always followed last.

Commands

The following commands are available. The respective docker-compose commands are in brackets.

  u   Create and start containers (up)
  p   Pull images (pull)
  s   Stop services (stop)
  d   Stop and remove containers (down)
  l   Show container logs (logs)
  a   Run shell in container (exec -it <service> sh)
  b   Build images (build)
  c   List containers (ps)
  t   List processes in containers (top)
  r   Build and push to registry (build, push)
  v   Scan container images for vulnerabilities
  E   Encrypt/seal secret file(s) with age (requires portmgr[secrets])
  D   Decrypt/unseal sealed secret files (requires portmgr[secrets])
  S   Show secret migration status (requires portmgr[secrets])
  M   Move literal environment values from the compose file into .env
  R   Rotate postgres/mariadb passwords and write new values to .env

You combine multiple commands. For example portmgr dul, runs docker compose with down, up and logs, thus stopping, removing and starting all containers and then showing the logs.

Commands are read the way tar reads its options: dul, -dul, -d -u -l and du -l are the same, but a word of command letters only counts in first position. Everything after the commands is an argument, never a command, so portmgr E pass seals the file pass. Only E (files) and D (--force) take arguments; a stray word such as portmgr du l is an error and runs nothing.

Building images

b and r read the build, image and platform of every service that has its own build: straight from the compose file and run docker compose -f .portmgr-build.yml build (r also push, or docker buildx bake with PORTMGR_MULTI_PLATFORM) on a temporary file holding only those keys, removed afterwards. A host that only builds images doesn't need the stack's .env, sealed extends files or anything else the rest of the compose file refers to. Services with profiles: are built only when COMPOSE_PROFILES names one of them.

Installation

sudo pip install portmgr

Or build it from source (here using the latest commit on master branch)

sudo pip install https://github.com/Craeckie/portmgr.git

Sealing secrets

portmgr can encrypt secret-bearing files (.env, config files) with age so they are safe to commit to git. Decryption happens once at setup time; the plaintext files remain on disk for Docker to use normally. With a seal-recipients.yml, each file is sealed only to the hosts that run it (their SSH keys) plus a recovery key; without one, all files share one passphrase. docs/sealing.md covers the recipients file, host and recovery keys, adding hosts and moving from a passphrase.

Requires the secrets extra:

pip install portmgr[secrets]

Move secrets out of the compose file first (run inside a service directory, or above it to go through every stack):

portmgr M

Lists each literal environment: value with secret-looking keys (password, token, key, …) preselected, asks which to move, previews the result and asks for confirmation. Each chosen value is appended to .env (created with mode 600 if missing) and replaced in the compose file with "${NAME}"; nothing else in the compose file changes, comments included. NAME is the key itself, or <SERVICE>_<KEY> when that name is already used with another value, is referenced elsewhere in the file, or is set in your shell (which would override .env). Values that already reference a variable, span several lines, use YAML anchors or tags, or that compose would re-type (True, 0o17, 1.50, …; quote them to move them) are left alone with a note. Then seal .env as below and commit the compose file.

Seal a file (run inside a service directory):

portmgr E .env

This creates .env.age and writes a .migrated marker. Commit the .age file and .migrated; never commit the plaintext — E does not touch .gitignore, so make sure .env is ignored yourself.

Decrypt on a new server (run from any ancestor directory):

portmgr D

Recurses via dckrsub.yml and decrypts every *.age in each stack's directory and below it whose plaintext is missing. Files not sealed for this host are skipped. Use portmgr D --force to overwrite existing plaintext from the sealed copy.

Outside a compose tree, or for the whole tree at once, use portseal (installed with portmgr):

portseal e <file>…        # seal
portseal d [path…]        # unseal every *.age below the paths
portseal k [path…]        # reseal files whose recipients changed
portseal s [path…]        # show who can unseal each file

Check migration progress:

portmgr S

Reports DONE, PENDING, or CLEAN for each service and prints a summary tally. A .migrated marker always means DONE, even if the compose file still contains what looks like a secret — create it by hand for services that need no sealing. CLEAN only means nothing was detected; portmgr u's footer still counts a CLEAN service as unsealed until it has a .migrated.

Rotate database passwords:

portmgr R

Finds postgres and mariadb/mysql services in each compose stack, generates a new random password, runs ALTER USER in the running container, and writes the new value(s) to .env. For mariadb/mysql it uses the mariadb client, or mysql where that is the only one (e.g. mysql/mysql-server), and changes the password of every host entry of the account (root@localhost and root@% alike). The value goes into .env under the variable the compose file reads: MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASS}" updates MYSQL_ROOT_PASS. A value that mixes a reference with other text (pre${X}) is not rotated. If a password was previously hardcoded in the compose file rather than referenced via ${VAR}, a warning is printed reminding you to update the compose file to use the variable reference.

Every rotated password is printed under its .env name, with the old and the new value each on its own old: / new: line, also when only part of a service could be rotated, so you can replace the old value wherever else it is configured. The output contains the passwords in clear text; keep it out of logs you share. Re-seal .env with portmgr E .env afterwards if you keep a .env.age.

Keys: files sealed to host keys are unsealed with ~/.ssh/id_ed25519, or the keys in PORTMGR_IDENTITY (comma-separated paths). For passphrase-sealed files portmgr prompts once and caches the passphrase for the rest of the run; for non-interactive use, set PORTMGR_PASSPHRASE=<passphrase>.

After running portmgr u, a footer line is printed if any services have not yet been sealed.

Tipps

If you use portmgr a lot like me, you might want to shorten it to one letter. For bash, you can add alias p='portmgr' to ~/.bashrc. For fish-shell you can add abbr p portmgr to ~/.config/fish/config.fish. The same works for portseal, e.g. alias pz=portseal.

Metadata

Release files for portmgr 1.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for portmgr 1.14.0
File Size Uploaded Provenance Actions
portmgr-1.14.0.tar.gz 65.9 kB With provenance Details for portmgr-1.14.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for portmgr 1.14.0
File Interpreter ABI Platform Actions
portmgr-1.14.0-py3-none-any.whl Python 3 none any Details for portmgr-1.14.0-py3-none-any.whl

Total release size: 104.3 kB

Release files / portmgr-1.14.0.tar.gz

Download URL portmgr-1.14.0.tar.gz
Size 65.9 kB
Tags Source
SHA-256 checksum
How to use checksums
067448a5909e8b02783d0dd74e943932be32bd45b0b95a22ca2535aa51079679
BLAKE2b-256 checksum
How to use checksums
467a3f0b93f5b8c51c905ec05619d6bbdcf040c0476439b01fbaf42e491379be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / portmgr-1.14.0-py3-none-any.whl

Download URL portmgr-1.14.0-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d22af07142c305d85efa9cc04e00f517b57f26ebb166002beb9df31223269f7
BLAKE2b-256 checksum
How to use checksums
36b8b85f5a4f77dea228b47a00e2ea7f8e49eb635c8acbe9f8b37db9f89f5c89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for portmgr 1.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for portmgr-1.14.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.14.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page