Skip to content

fix(up): surface Docker connection errors before missing config - #13972

Open
scarab-systems wants to merge 4 commits into
docker:mainfrom
scarab-systems:13649-preserve-docker-socket-error
Open

fix(up): surface Docker connection errors before missing config#13972
scarab-systems wants to merge 4 commits into
docker:mainfrom
scarab-systems:13649-preserve-docker-socket-error

Conversation

@scarab-systems

@scarab-systems scarab-systems commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

What I did

This updates docker compose up so that, when no compose file was explicitly selected and default discovery has no compose file candidate to load, Compose checks the Docker API connection before returning the missing-config error. That lets the Moby client surface the daemon/socket connection error for the empty-directory case reported in #13649.

The guard is intentionally narrow. It does not run ahead of explicit config loading: -f, COMPOSE_FILE, env-file based configuration, .env defining COMPOSE_FILE, or an existing default compose file all keep the normal Compose project-loading path. This preserves the COMPOSE_FILE-points-to-directory behavior discussed in review.

Related issue

Fixes #13649

Testing

  • go test ./cmd/compose -run 'TestUp(ChecksDockerConnectionBeforeDefaultConfigDiscovery|LoadsConfigBeforeDockerConnection)$' -count=1
  • go test ./cmd/compose ./pkg/compose -count=1
  • make lint
  • make test
  • make validate
  • make build
  • Manual smoke: empty directory plus unreadable Docker socket now returns permission denied while trying to connect to the docker API ....
  • Manual smoke: explicit COMPOSE_FILE pointing at a directory still returns read ... is a directory.
  • make build-and-e2e attempted locally. It still fails in this Docker Desktop environment on TestImageVolume, TestImageVolumeRecreateOnRebuild, and TestComposeModel; those same local/base failures were reproduced previously on clean current origin/main.

(not mandatory) A picture of a cute animal, if possible in relation to what you did

Scarab Systems mascot

Signed-off-by: ScarabSystems <scarab.systems@yahoo.com>
Comment thread cmd/compose/up.go Outdated
if err := validateFlags(&up, &create); err != nil {
return err
}
return checkDockerConnection(ctx, dockerCli)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this should be inside runUp to avoid connecting to the API before all other validation is completed (at least at a glance it feels like a more natural place to validate the connection)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this against the command path after your note. runUp is reached after the project has already been loaded by p.WithServices(...); the misleading is a directory error from #13649 is raised during that earlier project-loading path, so moving the ping into runUp would leave the reported case unchanged.

I kept the reachability check after local validation but before project loading, and moved the remaining --attach / --attach-dependencies conflict into validateFlags so that flag-only validation still wins before any Docker API call. Added coverage for both paths. If there is another pre-load owner you prefer for the connection check, I can adjust the placement.

Move the --attach/--attach-dependencies conflict into validateFlags so local flag validation still completes before the Docker API reachability check added for docker#13649.

Add a regression test that exercises the conflict without expecting a Docker client call.

Verification:

- go test ./cmd/compose -run 'TestUp(ReturnsDockerConnectionErrorBeforeConfigPathFallback|ValidatesFlagConflictsBeforeDockerConnection)' -count=1

- go test ./cmd/compose ./pkg/compose -count=1

- make test

- make build-and-e2e (fails on base-reproduced e2e tests: TestImageVolume, TestImageVolumeRecreateOnRebuild, TestComposeModel)

Signed-off-by: ScarabSystems <scarab.systems@yahoo.com>
@scarab-systems
scarab-systems marked this pull request as ready for review July 26, 2026 21:42
@scarab-systems
scarab-systems requested review from a team as code owners July 26, 2026 21:42
@scarab-systems
scarab-systems requested review from glours and ndeloof July 26, 2026 21:42
@ndeloof

ndeloof commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

#13649 is actually unrelated to docker.sock permission
This is well reported by moby Client with a dedicated error message.
We could check the client is well set on first call to apiClient() relying on a sync.Once block

Rework the previous command-level Docker ping after maintainer feedback. The earlier approach made up check the Docker client before project loading, which can mask local Compose file load errors such as COMPOSE_FILE pointing at a directory.

Remove that premature ping and the related attach-flag validation reshuffle, and keep a regression test that proves up loads configuration before reaching the Docker client.

Verification:

- go test ./cmd/compose -run TestUpLoadsConfigBeforeDockerConnection -count=1

- go test ./cmd/compose ./pkg/compose -count=1

- make lint

- make test

- make validate

- make build-and-e2e attempted: plugin-mode e2e reproduces image-volume and model failures on current origin/main in this local Docker Desktop environment

Signed-off-by: ScarabSystems <scarab.systems@yahoo.com>
@scarab-systems scarab-systems changed the title fix: surface Docker connection errors before project load test: preserve config load before client use Aug 10, 2026
@scarab-systems

scarab-systems commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

I updated the branch again after a deeper pass through the empty-directory path.

The branch now includes a production fix, not only the config-order regression test. For docker compose up, when no compose file is explicitly selected and default discovery has no candidate, Compose now checks the Docker API connection before returning the missing-config error. That lets the Moby client surface the daemon/socket connection error for the #13649 empty-directory case.

The guard stays narrow and preserves the config-loading behavior you pointed out: if config selection is explicit (-f, COMPOSE_FILE, env files, .env defining COMPOSE_FILE) or a default compose file exists, Compose keeps the normal project-loading path. The existing regression test still proves a COMPOSE_FILE directory reports read ... is a directory.

Validation run locally:

  • go test ./cmd/compose -run 'TestUp(ChecksDockerConnectionBeforeDefaultConfigDiscovery|LoadsConfigBeforeDockerConnection)$' -count=1
  • go test ./cmd/compose ./pkg/compose -count=1
  • make lint
  • make test
  • make validate
  • make build
  • Manual smoke: empty directory plus unreadable Docker socket returns permission denied while trying to connect to the docker API ....
  • Manual smoke: explicit COMPOSE_FILE directory still returns read ... is a directory.
  • make build-and-e2e attempted locally. It still fails in this Docker Desktop environment on TestImageVolume, TestImageVolumeRecreateOnRebuild, and TestComposeModel; those same local/base failures were reproduced previously on clean current origin/main.

@scarab-systems scarab-systems changed the title test: preserve config load before client use fix(up): surface Docker connection errors before missing config Aug 10, 2026
When docker compose up runs without an explicit compose file and default discovery has no candidate, ping the Docker API before returning the missing-config error. This preserves explicit config-file failures from -f, COMPOSE_FILE, env files, .env COMPOSE_FILE, and existing default compose files.

Adds a regression test proving the empty implicit-config path returns the Docker connection error, while the existing explicit COMPOSE_FILE directory test keeps config errors authoritative.

Validation: go test ./cmd/compose -run 'TestUp(ChecksDockerConnectionBeforeDefaultConfigDiscovery|LoadsConfigBeforeDockerConnection)$' -count=1; go test ./cmd/compose ./pkg/compose -count=1; make lint; make test; make validate; make build; manual smoke for permission-denied Docker socket and explicit COMPOSE_FILE directory. Full make build-and-e2e was also run and failed on the known local/base image-volume and model tests reproduced previously on clean origin/main.
Signed-off-by: ScarabSystems <scarab.systems@yahoo.com>
@scarab-systems
scarab-systems force-pushed the 13649-preserve-docker-socket-error branch from 0815336 to a137970 Compare August 10, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Misleading error message if user has no permission for docker socket

3 participants