Skip to content

composeUp with stacks removes every other stack's containers (--remove-orphans) #111

Closed

Description

@TMHSDigital

Summary

homelab_composeUp with stacks runs up -d --remove-orphans against only compose.base.yml plus the requested file. Every stack file lives in the same directory, so they all share one Compose project, and Compose removes the containers of every other stack as "orphans". Starting or updating one stack takes down the rest of the lab. homelab_composeDown with stacks has the mirror problem: it always adds compose.base.yml, so stopping one stack also stops every base service.

Related: #93

Where

  • mcp-server/src/utils/compose.ts:239 (buildComposeCommand), :243-245
  • mcp-server/src/tools/composeUp.ts:32
  • mcp-server/src/tools/composeDown.ts:35
  • skills/docker-compose-stacks/SKILL.md:46-48, :136

Details

if (stacks && stacks.length > 0) {
  const files = ["-f compose.base.yml", ...stacks.map((s) => `-f ${s}`)].join(" ");
  return `${cd}; docker compose ${files} ${action}`;
}

composeUp passes action = "up -d --remove-orphans 2>&1". Compose names the project after the project directory (or a shared top-level name:), which is the same for every file in HOMELAB_COMPOSE_DIR. Containers of that project whose service is not in the files passed are orphans, and --remove-orphans deletes them.

The docker-compose-stacks skill recommends exactly this call for deploys and updates (homelab_composePull then homelab_composeUp with the same stacks) and says orphan removal only cleans "containers removed from the selected compose files", which is not what Compose does.

Impact

The documented "update one stack" workflow removes the containers of all other stacks (DNS, reverse proxy, password manager, ...). composeDown of a single stack also stops the base stack and its network.

Steps to reproduce

  1. Reference layout in /opt/homelab/docker with all stack files up.
  2. Call homelab_composeUp with { "stacks": ["compose.monitoring.yml"], "confirm": true }.
  3. Compose reports "Found orphan containers" and removes the containers from the apps, network, security, storage and tools files.

Suggested fix

  • With a stack subset, do not pass --remove-orphans. Better: always pass the full file list (so the project config is complete) and target the stack's services: docker compose <all files> up -d <services>, where the services come from docker compose -f <stack> config --services.
  • For composeDown with stacks, stop and remove only that stack's services (docker compose <all files> stop <services> then rm -f <services>) instead of down on base + stack.
  • Keep --remove-orphans only for the "all stacks" path.
  • Correct the skill text at SKILL.md:136.

Acceptance criteria

  • composeUp with stacks never removes containers that belong to other stack files.
  • composeDown with stacks leaves base services running.
  • Command tests cover the stack-subset case for up and down (today confirm-gates.test.ts:61 only checks the no-stacks command).
  • Skill describes the real behavior.

Getting started

  • Relevant files: mcp-server/src/utils/compose.ts, mcp-server/src/tools/composeUp.ts, mcp-server/src/tools/composeDown.ts, mcp-server/src/tools/__tests__/commands.test.ts
  • How to run tests: cd mcp-server && npm install && npm test

Filed by repo-audit/full-audit at a59395f. Severity: high. Effort: M. audit-key: bug|mcp-server/src/utils/compose.ts|buildComposeCommand

Activity

  1. added
    bug
    severity: high
    on Nov 18, 2026
  2. TMHSDigital commented on Nov 18, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 70e28d3. With stacks, composeUp and composeDown now pass the full project file list and act only on the named stack's services (no --remove-orphans for a subset; composeDown uses stop + rm and refuses removeVolumes). Verified with new command and handler tests (350 passing) and by running the generated script against a stub docker, which started/removed only the stack's services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmcp-serverseverity: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions