index.js 431 B

1234567891011121314151617181920212223
  1. import fs from 'node:fs';
  2. import isDocker from 'is-docker';
  3. let cachedResult;
  4. // Podman detection
  5. const hasContainerEnv = () => {
  6. try {
  7. fs.statSync('/run/.containerenv');
  8. return true;
  9. } catch {
  10. return false;
  11. }
  12. };
  13. export default function isInsideContainer() {
  14. // TODO: Use `??=` when targeting Node.js 16.
  15. if (cachedResult === undefined) {
  16. cachedResult = hasContainerEnv() || isDocker();
  17. }
  18. return cachedResult;
  19. }