Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Platform.php

function Platform::isDocker

2 calls to Platform::isDocker()
Application::doRun in vendor/composer/composer/src/Composer/Console/Application.php
Runs the current application.
Platform::isWindowsSubsystemForLinux in vendor/composer/composer/src/Composer/Util/Platform.php

File

vendor/composer/composer/src/Composer/Util/Platform.php, line 188

Class

Platform
Platform helper for uniform platform-specific tests.

Namespace

Composer\Util

Code

public static function isDocker() : bool {
    if (null !== self::$isDocker) {
        return self::$isDocker;
    }
    // cannot check so assume no
    if ((bool) ini_get('open_basedir')) {
        return self::$isDocker = false;
    }
    // .dockerenv and .containerenv are present in some cases but not reliably
    if (file_exists('/.dockerenv') || file_exists('/run/.containerenv') || file_exists('/var/run/.containerenv')) {
        return self::$isDocker = true;
    }
    // see https://www.baeldung.com/linux/is-process-running-inside-container
    $cgroups = [
        '/proc/self/mountinfo',
        // cgroup v2
'/proc/1/cgroup',
    ];
    foreach ($cgroups as $cgroup) {
        if (!is_readable($cgroup)) {
            continue;
        }
        // suppress errors as some environments have these files as readable but system restrictions prevent the read from succeeding
        // see https://github.com/composer/composer/issues/12095
        try {
            $data = @file_get_contents($cgroup);
        } catch (\Throwable $e) {
            break;
        }
        if (is_string($data) && str_contains($data, '/var/lib/docker/')) {
            return self::$isDocker = true;
        }
    }
    return self::$isDocker = false;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal