mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
21 lines
634 B
JavaScript
21 lines
634 B
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const readFileSync = require('./fs/readFileSync');
|
|
const fileExistsSync = require('./fs/fileExistsSync');
|
|
|
|
/* Check if is inside docker container */
|
|
module.exports = function isDockerContainer() {
|
|
// wrap in try catch to make sure that missing permissions won't break anything
|
|
try {
|
|
const cgroupFilePath = path.join('/', 'proc', '1', 'cgroup');
|
|
if (fileExistsSync(cgroupFilePath)) {
|
|
const cgroupFileContent = readFileSync(cgroupFilePath).toString();
|
|
return !!cgroupFileContent.match(/docker/);
|
|
}
|
|
} catch (exception) {
|
|
// do nothing
|
|
}
|
|
return false;
|
|
};
|