Skip to content

stop/kill/pause/logs/rm/down/ps/events silently no-op or give a raw error when targeting a job name #14249

Description

@ndeloof

"This issue was filed by an AI agent on a human's behalf. The human submitter may not have independently verified the report."

What this issue is about

PR #14093 fixed create and start so that targeting a declared jobs: entry (instead of a services: entry) gives a clear, actionable error instead of compose-go's raw no such service: <name> — and, when COMPOSE_PROJECT_NAME is set, instead of silently doing nothing.

That fix was scoped to create/start only. The same underlying helper, projectOrName (cmd/compose/compose.go), also backs stop, kill, pause, unpause, logs, rm, down, ps and events — none of which got the fix, so they still show both problems:

  1. Confusing raw error — without COMPOSE_PROJECT_NAME, targeting a job by name surfaces compose-go's generic no such service: <name> instead of a message pointing the user at docker compose run.
  2. Silent no-op — with COMPOSE_PROJECT_NAME set, projectOrName falls back to a label-driven, file-less project on any project-load failure (including "no such service"), swallowing the error entirely. Since a job that was never run left no container behind, the label-driven command finds nothing to act on and exits 0 as if it had succeeded.

Illustration

Given:

services:
  web:
    image: nginx

jobs:
  migrate:
    image: alpine
    command: ["echo", "migrating"]
    triggers:
      manual: true

Without COMPOSE_PROJECT_NAME:

$ docker compose stop migrate
no such service: migrate

Nothing here tells the user migrate is actually a valid job name and that docker compose run migrate is what they meant. Compare with start, fixed in #14093:

$ docker compose start migrate
job "migrate" can only be triggered with "docker compose run"

With COMPOSE_PROJECT_NAME set — as CI pipelines and scripts commonly do:

$ export COMPOSE_PROJECT_NAME=myproj
$ docker compose stop migrate; echo "exit=$?"
exit=0

No error, no output: stop silently did nothing.

Suggested fix

Generalize the jobTargetErr/unselectedJobs helpers introduced in #14093 (cmd/compose/run.go) to the other projectOrName callers — or fold the check directly into projectOrName so every caller benefits at once, rather than repeating the wiring per command.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions