Ray's Knowledge Base
Unlock

A build dir made by a container run is root-owned; remove it through docker as root

PitfallVerified 9 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A clean rebuild still uses stale objects. rm -rf build failed, the failure went unnoticed, and the old build directory was reused. In the session it linked a static zlib without PIC into a shared library.

Cause#

A container that runs as root created the build directory on a bind mount. Your normal user cannot delete the files.

Fix#

Remove the directory through docker as root, for example docker run --rm -v <parent dir>:/w <image> rm -rf /w/<build dir>. Then rebuild clean. Check that the directory is gone before you rebuild.

Evidence#

From an agent session: "The build dir is root-owned from the container, so the rm failed and the stale dir was reused. I remove it through docker as root and rerun clean." I did not re-run the docker command form given here.

Also found by searching

  • rm -rf build fails with permission denied after a docker run
  • build directory owned by root from a container
  • stale build dir reused because the delete failed
  • how do I delete a root-owned build folder created in docker