inDocker property
bool
get
inDocker
Returns true if we are running in a docker shell
Implementation
static bool get inDocker {
if (_inDocker == null) {
_inDocker = false;
/// Buildx no longer creates the /.dockerenv so we need
/// to check cgroups.
const pathToCgroup = '/proc/1/cgroup';
if (exists(pathToCgroup)) {
final lines = read(pathToCgroup).toList();
for (final line in lines) {
if (line.contains(':docker:')) {
_inDocker = true;
break;
}
}
}
if (_inDocker == false) {
/// At some point we should remove the ./dockerenv test
/// but I'm uncertain if the cgroup method works on older containers.
_inDocker = exists('/.dockerenv');
}
}
return _inDocker!;
}