提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
431 B

  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. }