Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
449 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | const fs = require('fs');
|
---|
3 |
|
---|
4 | let isDocker;
|
---|
5 |
|
---|
6 | function hasDockerEnv() {
|
---|
7 | try {
|
---|
8 | fs.statSync('/.dockerenv');
|
---|
9 | return true;
|
---|
10 | } catch (_) {
|
---|
11 | return false;
|
---|
12 | }
|
---|
13 | }
|
---|
14 |
|
---|
15 | function hasDockerCGroup() {
|
---|
16 | try {
|
---|
17 | return fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
---|
18 | } catch (_) {
|
---|
19 | return false;
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | module.exports = () => {
|
---|
24 | if (isDocker === undefined) {
|
---|
25 | isDocker = hasDockerEnv() || hasDockerCGroup();
|
---|
26 | }
|
---|
27 |
|
---|
28 | return isDocker;
|
---|
29 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.