Skip to content
Latchkey

Docker Build "too many open files" - Raise the ulimit for the Builder in CI

A RUN step opened more file descriptors than the builder allows. The default nofile ulimit is too low for the tool (a large compile, a bundler, a test runner), so it fails with "too many open files".

What this error means

The build fails inside a RUN step with too many open files, EMFILE, or pipe: too many open files. The same command runs fine on a host with a higher descriptor limit.

docker build output
#11 8.42 Error: EMFILE: too many open files, open '/app/node_modules/.../index.js'
#11 ERROR: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1

Common causes

The nofile ulimit is too low for the tool

Compilers, bundlers, and watchers open many files at once. When the descriptor limit inherited by the build is small, they exhaust it and fail.

Inherited daemon default carried into the build

BuildKit runs steps under the daemon’s default ulimits. If the host daemon’s nofile default is low, every build step inherits that ceiling.

How to fix it

Raise the file-descriptor limit for the build

Pass a higher --ulimit nofile so the RUN step has more descriptors.

Terminal
docker build --ulimit nofile=65536:65536 -t myorg/api:1.4.2 .

Set the builder default ulimit (BuildKit)

For buildx/BuildKit, configure the builder’s default ulimits so every build gets the higher limit.

buildkitd.toml
# buildkitd.toml on the builder
[worker.oci]
  max-parallelism = 4
  defaultCgroupParent = ""
# or pass --ulimit per build as above

How to prevent it

  • Set a generous --ulimit nofile for descriptor-heavy builds.
  • Raise the daemon/builder default nofile on runner images.
  • Lower build parallelism when a tool is descriptor-hungry.

Frequently asked questions

What causes ""too many open files""?
Compilers, bundlers, and watchers open many files at once. When the descriptor limit inherited by the build is small, they exhaust it and fail.
How do I fix "too many open files"?
Pass a higher --ulimit nofile so the RUN step has more descriptors.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card