docker/compose · error

--detach cannot be combined with --abort-on-container-exit,

Error message

--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch

What it means

Returned by validateFlags when the user explicitly passes --detach (-d) together with any of --attach-dependencies, --abort-on-container-exit, --abort-on-container-failure, --attach SERVICE, or --watch. All of those flags require foreground mode to stream output or observe container exits; the '--detach' variant of the message is used because --wait was not what set Detach. This is the mirror of the --wait variant at up.go:211.

Source

Thrown at cmd/compose/up.go:213

		up.cascadeStop = true
	}
	if up.cascadeStop && up.cascadeFail {
		return fmt.Errorf("--abort-on-container-failure cannot be combined with --abort-on-container-exit")
	}
	if up.wait {
		if up.attachDependencies || up.cascadeStop || len(up.attach) > 0 {
			return fmt.Errorf("--wait cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies")
		}
		up.Detach = true
	}
	if create.Build && create.noBuild {
		return fmt.Errorf("--build and --no-build are incompatible")
	}
	if up.Detach && (up.attachDependencies || up.cascadeStop || up.cascadeFail || len(up.attach) > 0 || up.watch) {
		if up.wait {
			return fmt.Errorf("--wait cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
		} else {
			return fmt.Errorf("--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
		}
	}
	if create.noInherit && create.noRecreate {
		return fmt.Errorf("--no-recreate and --renew-anon-volumes are incompatible")
	}
	if create.forceRecreate && create.noRecreate {
		return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
	}
	if create.recreateDeps && create.noRecreate {
		return fmt.Errorf("--always-recreate-deps and --no-recreate are incompatible")
	}
	if create.noBuild && up.watch {
		return fmt.Errorf("--no-build and --watch are incompatible")
	}
	return nil
}

//nolint:gocyclo

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Run foreground for attach/watch semantics: drop -d/--detach.
  2. Keep -d and get logs/exit behavior another way: `up -d` then `docker compose logs -f` or `docker compose wait`.
  3. Remove -d from aliases/wrappers when the command line already contains attach/abort/watch flags.

Example fix

# before
docker compose up -d --attach web

# after
docker compose up --attach web   # foreground
# or detached alternative:
docker compose up -d && docker compose logs -f web
Defensive patterns

Strategy: validation

Validate before calling

if [[ "$UP_FLAGS" == *-d* || "$UP_FLAGS" == *--detach* ]]; then
  for f in --attach --attach-dependencies --abort-on-container-exit --abort-on-container-failure --watch; do
    [[ "$UP_FLAGS" == *"$f"* ]] && { echo "--detach conflicts with $f" >&2; exit 2; }
  done
fi

Prevention

When it happens

Trigger: `docker compose up -d --attach web`; `up -d --watch`; `up -d --abort-on-container-exit`; `up --detach --attach-dependencies`. Shell aliases like `alias cup='docker compose up -d'` then appending --watch manually.

Common situations: A 'detached by default' alias or COMPOSE_FILE wrapper where users add watch/attach flags; CI scripts that always pass -d and later gain abort/exit-code flags for failure propagation.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/c03b0cceb6ba5648. Report an issue: GitHub.