DEV Community

HiroItozzz
HiroItozzz

Posted on

Stop Typing Long Docker Compose Commands — compose-lazy Does It Interactively

If you work with Docker Compose daily, you've typed some version of this hundreds of times:

docker compose -f docker-compose.prod.yml --profile dev exec app bash
Enter fullscreen mode Exit fullscreen mode

compose-lazy is a CLI tool I built to cut that down. It provides shorthand commands for the most common docker compose workflows, and — more usefully — lets you pick compose files, profiles, and services interactively instead of remembering or typing them.

pipx install compose-lazy
# or
uv tool install compose-lazy
Enter fullscreen mode Exit fullscreen mode

Three commands are added to your PATH: dcp, dcpu, and dcpe.


The basics: shorter commands

# docker compose up --build -d
dcpu -b -d

# docker compose exec app bash
dcpe app

# docker compose logs app -f
dcp l app -fo

# docker compose stop
dcp s
Enter fullscreen mode Exit fullscreen mode

The aliases map closely to the originals — dcpu is always docker compose up, dcpe is always docker compose exec, and dcp is a general-purpose entry point for everything else (build, restart, ps, logs, stop, down, ...).


The useful part: interactive selection

This is where compose-lazy earns its name. Pass an option flag without a value and it reads your project and prompts you to choose.

Pick a compose file with -f

$ dcpu -f
☑ Found 2 compose files!
    1. docker-compose.yml
    2. docker-compose.prod.yml
Enter your choices (e.g., 1,3,4) or 'q' to quit: 2
▷ Executing `docker compose -f docker-compose.prod.yml up`.
Enter fullscreen mode Exit fullscreen mode

Multiple selections work too — enter 1,2 to use both files.

Pick a profile with -pf

$ dcp re -pf
☑ Found 2 profiles!
    1. dev
    2. prod
Enter your choices (e.g., 1,3,4) or 'q' to quit: 1
▷ Executing `docker compose --profile dev restart`.
Enter fullscreen mode Exit fullscreen mode

Pick a service with -s

$ dcp l -s
☑ Found 3 services!
    1. app
    2. db
    3. frontend
Enter your choices (e.g., 1,3,4) or 'q' to quit: 1,2
▷ Executing `docker compose logs app db`.
Enter fullscreen mode Exit fullscreen mode

For exec and run, the service prompt appears automatically when no service is given — no -s needed:

$ dcpe
☑ Found 3 services!
    1. app
    2. db
    3. frontend
Enter your choice or 'q' to quit: 1
▷ Executing `docker compose exec app bash`.
Enter fullscreen mode Exit fullscreen mode

There's also a small quality-of-life detail: dcpe uv run pytest auto-detects that uv isn't a service name, falls back to interactive service selection, and carries uv run pytest forward as the inner command.


Workspace management: operate multiple repos at once

The workspace feature is for projects that span multiple repositories. Register repos into a named workspace and run commands across all of them with a single prompt.

Register a repo

$ dcp ws register
Please enter a new directory path: /path/to/repo
☑ Found 2 docker-compose files!
    1. docker-compose.yml
    2. docker-compose.prod.yml
Enter your choices (e.g., 1,3,4) or 'q' to quit: 1

☑ Found 1 registered workspace!
    1. myproject
Or '0' for a new entry.
Enter your choice or 'q' to quit: 0
Please enter a new workspace name: myproject

☑ Registered new path to myproject: /path/to/repo (docker-compose.yml)
Enter fullscreen mode Exit fullscreen mode

You can register multiple repos into the same workspace. Each repo gets its own compose file pinned at registration time.

Bring up everything

$ dcp ws up
☑ Found 1 registered workspace!
    1. myproject
Enter your choice or 'q' to quit: 1

───── 📂 myproject ──────────────────────────────────────────────────────────
▷ Executing `docker compose -f docker-compose.yml up -d` in MYPROJECT.
Enter fullscreen mode Exit fullscreen mode

All workspace subcommands:

Command What it runs
dcp ws register(reg) Register a repo interactively
dcp ws delete(del) Remove a repo
dcp ws list(li) Show all workspaces and their repos
dcp ws up(u) docker compose up -d across all repos
dcp ws build(b) docker compose build across all repos
dcp ws restart(re) docker compose restart across all repos
dcp ws stop(s) docker compose stop across all repos
dcp ws down docker compose down across all repos

Config lives in ~/.config/compose-lazy/config.yml.


Requirements

  • Python 3.11+
  • Docker with Compose V2 (docker compose, not docker-compose)

🔗 PyPI | GitHub

Top comments (0)