Summary
PR #8772 added --use-buildkit to shell out to the docker/finch CLI instead of using the Python Docker SDK. This is great for CI setups with a remote BuildKit endpoint (no local dockerd). However, ContainerClientFactory.create_client() still runs unconditionally and performs an Engine-API socket ping via the Docker SDK before --use-buildkit is evaluated. If that ping fails, the build exits before the BuildKit code path is reached — so --use-buildkit is effectively unreachable for its main target use case.
Related: #8649, whose maintainer comment foreshadowed this:
We are working on supporting BuildKit by allowing the CLI to be called directly when a parameter --use-buildkit is provided, meaning soon enough using the CLI instead of the SDK would be possible.
The SDK call is still the first thing that runs.
Environment
Reproducer
- Container with
docker CLI + buildx, no dockerd.
buildkitd sidecar on tcp://localhost:1234.
docker buildx create --name remote --driver remote tcp://localhost:1234 && docker buildx use remote
export DOCKER_HOST=tcp://localhost:1234 (required so docker buildx picks up the endpoint).
- Minimal template with one
PackageType: Image function + trivial Dockerfile.
sam build --use-buildkit (or --no-use-container, or neither).
Direct docker buildx build ... against the same endpoint succeeds.
Expected
With --use-buildkit, SAM shells out to docker (or finch). docker buildx handles the remote endpoint natively. Build succeeds.
Actual
Error: Running AWS SAM projects locally requires a container runtime.
Do you have Docker or Finch installed and running?
Debug log (sam build --use-buildkit --debug):
ContainerClientFactory.create_client() called
Trying Docker client creation
Creating Docker container client from environment variable.
Fall back docker api version to 1.44: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Docker daemon availability check failed with fallback: ('Connection aborted.', ...)
Docker client not created, trying creating Finch client.
Creating Finch container client with base_url=unix:///var/run/finch.sock
Finch daemon availability check failed: ('Connection aborted.', FileNotFoundError(2, ...))
No container runtime available
Telemetry: containerEngine: tcp-local, exitReason: ContainerNotReachableException.
Suggested fix
When --use-buildkit is set (or use_buildkit = true in samconfig.toml), skip the SDK-based Engine-API ping. Delegate all runtime availability checks to the CLI invocation itself — it will fail fast with a clearer error if the tooling isn't there.
Alternatively: if --use-buildkit implies "I have docker/finch on PATH," check for the CLI binary instead of pinging the Engine API socket.
Workaround
Run a docker:dind sidecar in the pod, point DOCKER_HOST=tcp://localhost:2375 only for sam build. Works, but duplicates the image-build stack (privileged DinD plus the existing BuildKit) just to satisfy the pre-check.
Summary
PR #8772 added
--use-buildkitto shell out to thedocker/finchCLI instead of using the Python Docker SDK. This is great for CI setups with a remote BuildKit endpoint (no localdockerd). However,ContainerClientFactory.create_client()still runs unconditionally and performs an Engine-API socket ping via the Docker SDK before--use-buildkitis evaluated. If that ping fails, the build exits before the BuildKit code path is reached — so--use-buildkitis effectively unreachable for its main target use case.Related: #8649, whose maintainer comment foreshadowed this:
The SDK call is still the first thing that runs.
Environment
dockerCLI 29.4.2 (no local dockerd), buildx 0.33.0 withremotedriver →tcp://localhost:1234moby/buildkit:v0.29.0sidecar ontcp://localhost:1234Reproducer
dockerCLI + buildx, nodockerd.buildkitdsidecar ontcp://localhost:1234.docker buildx create --name remote --driver remote tcp://localhost:1234 && docker buildx use remoteexport DOCKER_HOST=tcp://localhost:1234(required sodocker buildxpicks up the endpoint).PackageType: Imagefunction + trivial Dockerfile.sam build --use-buildkit(or--no-use-container, or neither).Direct
docker buildx build ...against the same endpoint succeeds.Expected
With
--use-buildkit, SAM shells out todocker(orfinch).docker buildxhandles the remote endpoint natively. Build succeeds.Actual
Debug log (
sam build --use-buildkit --debug):Telemetry:
containerEngine: tcp-local,exitReason: ContainerNotReachableException.Suggested fix
When
--use-buildkitis set (oruse_buildkit = trueinsamconfig.toml), skip the SDK-based Engine-API ping. Delegate all runtime availability checks to the CLI invocation itself — it will fail fast with a clearer error if the tooling isn't there.Alternatively: if
--use-buildkitimplies "I havedocker/finchon PATH," check for the CLI binary instead of pinging the Engine API socket.Workaround
Run a
docker:dindsidecar in the pod, pointDOCKER_HOST=tcp://localhost:2375only forsam build. Works, but duplicates the image-build stack (privileged DinD plus the existing BuildKit) just to satisfy the pre-check.