index.js 449 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const fs = require('fs');
  3. let isDocker;
  4. function hasDockerEnv() {
  5. try {
  6. fs.statSync('/.dockerenv');
  7. return true;
  8. } catch (_) {
  9. return false;
  10. }
  11. }
  12. function hasDockerCGroup() {
  13. try {
  14. return fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
  15. } catch (_) {
  16. return false;
  17. }
  18. }
  19. module.exports = () => {
  20. if (isDocker === undefined) {
  21. isDocker = hasDockerEnv() || hasDockerCGroup();
  22. }
  23. return isDocker;
  24. };