Skip to content

Instantly share code, notes, and snippets.

@gagomes
Created June 30, 2022 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagomes/bcea1a691c4a396538ad683d08dc1243 to your computer and use it in GitHub Desktop.
Save gagomes/bcea1a691c4a396538ad683d08dc1243 to your computer and use it in GitHub Desktop.
def container_id(pid)
  cgroup_file = "/proc/#{pid}/cgroup"
  return nil unless File.exist?(cgroup_file)

  container_id = File.foreach(cgroup_file)
    .map(&:strip)
    .select { |cg| cg.match?(/docker/) }.first
  container_id.split('/').last
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment