Skip to main content

Docker volume toolkit - copy/migrate volumes across a name-prefix change (CLI + interactive TUI)

Project description

docker-volume-toolkit

PyPI version Total PyPI downloads Python 3.10+ License: MIT

A small toolkit for Docker volumes. Its first command copies volumes from one name prefix to another - it matches every volume named {from_prefix}{tail} and copies it to {to_prefix}{tail}, preserving the tail (_home, _workspace, _certs, a per-user suffix, anything that follows the prefix). Run it from the host that owns the Docker volumes; it copies rather than renames, so the originals stay in place until you have verified the result.

Run with no arguments for the interactive TUI - designer, plan, execution:

Designer

Set the FROM and TO prefixes, an optional whole-name filter, the worker count, and the overwrite / remove-source toggles; a live counter shows how many discovered volumes match (5 of 20) and the BEFORE / AFTER panes preview the exact source and destination names.

Migration plan

Review each matched volume and its source → destination mapping; toggle rows with Space (a = all, n = none) and press Enter to run only the selected copies.

Execution

Live progress during the copy - an overall bar plus a per-volume bar for each parallel worker, moving through discovery and transfer.

When you need it

Docker namespaces volumes by COMPOSE_PROJECT_NAME (for example myproject_data, myproject_shared), and many stacks add a per-entity prefix of their own (jupyterlab-<user>). Whenever that prefix changes you would otherwise lose access to the existing data:

  • renaming a deployment (COMPOSE_PROJECT_NAME change) renames every <old-project>_* volume
  • an upstream platform reworking its volume names across an upgrade

The migrator moves the data onto the new names so nothing is lost across the rename.

Usage

Run with no arguments for the interactive TUI (designer → plan → execution):

./migrate_volumes.py

Or drive it entirely from the command line:

# preview the mapping without copying
./migrate_volumes.py --from myproject_ --to mynewproject_ --dry-run

# copy, skipping the prompt
./migrate_volumes.py --from myproject_ --to mynewproject_ --yes

# only the cert volumes, four parallel workers
./migrate_volumes.py --from myproject_ --to mynewproject_ --filter '_certs$' --workers 4

Options

  • --from PREFIX source volume name prefix (e.g. jupyterlab-)
  • --to PREFIX replacement destination prefix
  • --filter REGEX regex applied to the full source volume name (empty = all matches)
  • --workers N parallel copy containers (default 3)
  • --dry-run mount both volumes and verify access, copy nothing
  • --overwrite clean and replace a destination volume that already exists (default: error out and abort)
  • --remove-source delete each source volume after its successful copy (default: keep sources)
  • --yes skip the interactive plan and run from the CLI arguments

How it works

  • each copy runs rsync -aAX --delete inside a disposable alpine container - source mounted read-only, destination read-write; all metadata preserved
  • destinations are never recreated - with --overwrite the existing volume is kept and its contents mirrored from the source (--delete clears stale files)
  • sources are left intact by default; after the run the tool prints the docker volume rm commands for every volume it copied so you can clean up once verified
  • the --filter regex matches the whole source name; note Docker encodes . in volume names as -2e (e.g. alice.smith appears as alice-2esmith)

Install

Needs Docker (the tool shells out to docker volume and docker run) and Python 3.10+; rich>=13 and textual>=0.80 come with it.

Install from PyPI and run the CLI:

pip install docker-volume-toolkit
docker-volume-toolkit            # interactive TUI
docker-volume-toolkit --help     # CLI flags

Or skip installation entirely - the script carries an inline dependency block and a uv run --script shebang, so it auto-installs its own dependencies on first run:

./migrate_volumes.py

Without uv, install the dependencies once and run with any Python:

pip install rich textual
python migrate_volumes.py --help

It copies volumes from one prefix to another, and then it has no further reason to exist. You will run it twice and forget it. The volumes never say thank you.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_volume_toolkit-1.2.2.tar.gz (164.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_volume_toolkit-1.2.2-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file docker_volume_toolkit-1.2.2.tar.gz.

File metadata

  • Download URL: docker_volume_toolkit-1.2.2.tar.gz
  • Upload date:
  • Size: 164.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for docker_volume_toolkit-1.2.2.tar.gz
Algorithm Hash digest
SHA256 2c691c9022e3e5ea19cd0696fbebba65be4c407890cda7f12e0cf3b61bdcd644
MD5 fac626adc6f738dbd4198c060662c813
BLAKE2b-256 ec3b98eabb86a18671bda0869d35b7c17e0f1a041c7befd3a76601c3b785cd72

See more details on using hashes here.

File details

Details for the file docker_volume_toolkit-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for docker_volume_toolkit-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ad93eac3323909ca9a0095934632691de9b0d7107b52ffd099644c281a18696
MD5 b2a762ffc0171765a10296635273506d
BLAKE2b-256 56c4cdc44fcde5344ed2d156f2d1f78e4c686d3385632909094d139878cf66d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page