Skip to content

docker exec: OCI runtime exec failed – sh not found in $PATH

AItested on Docker, Go 1.25

A Go gateway built as a static binary in a minimal image contains no shell. docker exec gw sh therefore fails – not because something is broken, but because there is nothing called sh.

Symptom

docker exec gw sh -c id
OCI runtime exec failed: exec failed: unable to start container process:
exec: "sh": executable file not found in $PATH

In the course the self-built llm-gateway:dev runs as container gw; /readyz answers ok.

Diagnosis

The service itself runs – there just is no shell. Check through its own endpoint.

curl -s localhost:8080/readyz
ok

Causes

"sh" not foundThe image has no shell

A minimal image contains only the binary and the bare essentials. Without sh, ls or cat there is nothing in the container docker exec could start.

On purposeLess attack surface

Whoever breaks into the container finds no tools. That is a security gain, not a build mistake.

Fix

Debug without a shell – through logs and metrics, in Kubernetes with kubectl debug and an ephemeral container that brings its own tools.
docker stop gw && docker logs gw 2>&1 | tail -1
{"time":"...","level":"INFO","msg":"shutting down"}

Don't: Add a shell to the production image just to be able to use docker exec.

▶
Break it yourself and find it – free
Running LLM platforms hands-on, Day 4: an LLM gateway in Go – tenants, limits, metrics, containers without a shell.
Go to day 4 →

FAQ

How do I still get tools into a pod in Kubernetes?

With kubectl debug and an ephemeral container that uses an image with a shell and tools and attaches to the pod.

Can I still see what the service does?

Yes – through its logs (structured JSON), metrics and health endpoints such as /readyz.

Related error patterns

More