Skip to content

Detect Docker without spawning grep - #91

Open
OskarEichler wants to merge 1 commit into
rdp:masterfrom
OskarEichler:codex/docker-cgroup-v2
Open

OskarEichler wants to merge 1 commit into
rdp:masterfrom
OskarEichler:codex/docker-cgroup-v2

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

OS::Underlying.docker? currently shells out to grep and only recognizes cgroup paths containing docker. Docker using cgroup v2 can expose root membership such as 0::/, so the predicate returns false even inside the container; every call also creates a subprocess.

This checks /.dockerenv first, streams cgroup membership as a fallback, and returns false when Linux metadata is unavailable. It intentionally remains Docker-specific and does not classify Podman.

Verification

  • added focused regressions for cgroup-v2, cgroup markers, and unavailable metadata
  • Ruby 4.0.6: 39 examples, 0 failures
  • combined candidates: 42 examples, 0 failures on Ruby 4.0.6 and 3.2.11
  • syntax and diff checks pass

Changing non-Linux or unavailable results from nil to false makes the predicate consistently boolean.

Use /.dockerenv for cgroup-v2 containers, retain cgroup marker detection, and return a stable false when Linux metadata is unavailable.
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.

1 participant