diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 8ddeb17..370cfba 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -530,12 +530,8 @@ public function discoverServiceProviders() {
         }
       }
     }
-    if ($container_yamls = Settings::get('container_yamls')) {
-      $this->serviceYamls['site'] = $container_yamls;
-    }
-    $site_services_yml = $this->getSitePath() . '/services.yml';
-    if (file_exists($site_services_yml) && is_readable($site_services_yml)) {
-      $this->serviceYamls['site'][] = $site_services_yml;
+    if (!$this->addServiceFiles(Settings::get('container_yamls'))) {
+      throw new \Exception('The container_yamls settings is missing.');
     }
   }
 
@@ -1295,4 +1291,21 @@ protected static function setupTrustedHosts(Request $request, $hostPatterns) {
 
     return TRUE;
   }
+
+  /**
+   * Add service files.
+   *
+   * @param $service_yamls
+   *   A list of service files.
+   *
+   * @return bool
+   *   TRUE if the list was an array, FALSE otherwise.
+   */
+  protected function addServiceFiles($service_yamls) {
+    if (is_array($service_yamls)) {
+      $this->serviceYamls['site'] = array_filter($service_yamls, 'file_exists');
+      return TRUE;
+    }
+    return FALSE;
+  }
 }
diff --git a/core/lib/Drupal/Core/Installer/InstallerKernel.php b/core/lib/Drupal/Core/Installer/InstallerKernel.php
index 4063611..41e8cbe 100644
--- a/core/lib/Drupal/Core/Installer/InstallerKernel.php
+++ b/core/lib/Drupal/Core/Installer/InstallerKernel.php
@@ -40,4 +40,11 @@ public function resetConfigStorage() {
     $this->configStorage = NULL;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function addServiceFiles($service_yamls) {
+    // In the beginning there is no settings.php and no service YAMLs.
+    return parent::addServiceFiles($service_yamls ?: []);
+  }
 }
diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
index a6dc573..fa9fd51 100644
--- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php
+++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
@@ -55,6 +55,7 @@ public function boot() {
     if (!Settings::getAll()) {
       new Settings(array(
         'hash_salt' => 'run-tests',
+        'container_yamls' => [],
         // If there is no settings.php, then there is no parent site. In turn,
         // there is no public files directory; use a custom public files path.
         'file_public_path' => 'sites/default/files',
diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php
index e5d076a..d2c5341 100644
--- a/core/modules/simpletest/src/KernelTestBase.php
+++ b/core/modules/simpletest/src/KernelTestBase.php
@@ -135,11 +135,16 @@ protected function prepareConfigDirectories() {
   protected function setUp() {
     $this->keyValueFactory = new KeyValueMemoryFactory();
 
+    // Back up settings from TestBase::prepareEnvironment().
+    $settings = Settings::getAll();
+
     // Allow for test-specific overrides.
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
     if (file_exists($settings_services_file)) {
       // Copy the testing-specific service overrides in place.
-      copy($settings_services_file, DRUPAL_ROOT . '/' . $this->siteDirectory . '/services.yml');
+      $testing_services_file = DRUPAL_ROOT . '/' . $this->siteDirectory . '/services.yml';
+      copy($settings_services_file, $testing_services_file);
+      $this->settingsSet('container_yamls', [$testing_services_file]);
     }
 
     // Create and set new configuration directories.
@@ -149,8 +154,6 @@ protected function setUp() {
     // @todo Remove the indirection; implement ServiceProviderInterface instead.
     $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
 
-    // Back up settings from TestBase::prepareEnvironment().
-    $settings = Settings::getAll();
     // Bootstrap a new kernel. Don't use createFromRequest so we don't mess with settings.
     $class_loader = require DRUPAL_ROOT . '/core/vendor/autoload.php';
     $this->kernel = new DrupalKernel('testing', $class_loader, FALSE);
diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php
index 9259845..b4901af 100644
--- a/core/modules/simpletest/src/TestBase.php
+++ b/core/modules/simpletest/src/TestBase.php
@@ -1210,6 +1210,7 @@ private function prepareEnvironment() {
     new Settings(array(
       // For performance, simply use the database prefix as hash salt.
       'hash_salt' => $this->databasePrefix,
+      'container_yamls' => [],
     ));
 
     drupal_set_time_limit($this->timeLimit);
diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
index 59ee3f3..cc2138d 100644
--- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
+++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelSiteTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\system\Tests\DrupalKernel;
 
+use Drupal\Core\Site\Settings;
 use Drupal\simpletest\KernelTestBase;
 
 /**
@@ -20,6 +21,9 @@ class DrupalKernelSiteTest extends KernelTestBase {
    * Tests services.yml in site directory.
    */
   public function testServicesYml() {
+    $container_yamls = Settings::get('container_yamls');
+    $container_yamls[] = $this->siteDirectory . '/services.yml';
+    $this->settingsSet('container_yamls', $container_yamls);
     $this->assertFalse($this->container->has('site.service.yml'));
     // A service provider class always has precedence over services.yml files.
     // KernelTestBase::buildContainer() swaps out many services with in-memory
diff --git a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
index 44ae20f..af8ce27 100644
--- a/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
+++ b/core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php
@@ -54,6 +54,7 @@ protected function getTestKernel(Request $request, array $modules_enabled = NULL
     // Manually create kernel to avoid replacing settings.
     $class_loader = require DRUPAL_ROOT . '/core/vendor/autoload.php';
     $kernel = DrupalKernel::createFromRequest($request, $class_loader, 'testing');
+    $this->settingsSet('container_yamls', []);
     $this->settingsSet('hash_salt', $this->databasePrefix);
     if (isset($modules_enabled)) {
       $kernel->updateModules($modules_enabled);
@@ -169,6 +170,7 @@ public function testRepeatedBootWithDifferentEnvironment() {
 
     foreach ($environments as $environment) {
       $kernel = DrupalKernel::createFromRequest($request, $class_loader, $environment);
+      $this->settingsSet('container_yamls', []);
       $this->settingsSet('hash_salt', $this->databasePrefix);
       $kernel->boot();
     }
diff --git a/core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php b/core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php
new file mode 100644
index 0000000..31e0b9d
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php
@@ -0,0 +1,59 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\DrupalKernel\DiscoverServiceProvidersTest.
+ */
+
+namespace Drupal\Tests\Core\DrupalKernel;
+
+use Drupal\Core\DrupalKernel;
+use Drupal\Core\Site\Settings;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\DrupalKernel
+ * @group DrupalKernel
+ */
+class DiscoverServiceProvidersTest extends UnitTestCase {
+
+  /**
+   * Tests discovery with user defined container yaml.
+   *
+   * @covers ::discoverServiceProviders()
+   */
+  public function testDiscoverServiceCustom() {
+    new Settings(array(
+      'container_yamls' => array(
+        __DIR__ . '/fixtures/custom.yml'
+      ),
+    ));
+
+    $kernel = new DrupalKernel('prod', new \Composer\Autoload\ClassLoader());
+    $kernel->discoverServiceProviders();
+
+    $expect = array(
+      'app' => array(
+        'core' => 'core/core.services.yml',
+      ),
+      'site' => array(
+        __DIR__ . '/fixtures/custom.yml',
+      ),
+    );
+
+    $this->assertAttributeSame($expect, 'serviceYamls', $kernel);
+  }
+
+  /**
+   * Tests the exception when container_yamls is not set.
+   *
+   * @covers ::discoverServiceProviders()
+   * @expectedException \Exception
+   */
+  public function testDiscoverServiceNoContainerYamls() {
+    new Settings([]);
+    $kernel = new DrupalKernel('prod', new \Composer\Autoload\ClassLoader());
+    $kernel->discoverServiceProviders();
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Core/DrupalKernel/fixtures/custom.yml b/core/tests/Drupal/Tests/Core/DrupalKernel/fixtures/custom.yml
new file mode 100644
index 0000000..3950896
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/DrupalKernel/fixtures/custom.yml
@@ -0,0 +1,3 @@
+parameters:
+  test.config:
+    test: true
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index 7cc10be..8a3dfa4 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -595,6 +595,11 @@
 # $config['system.performance']['fast_404']['html'] = '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>';
 
 /**
+ * Load services definition file.
+ */
+$settings['container_yamls'][] = __DIR__ . '/services.yml';
+
+/**
  * Load local development override configuration, if available.
  *
  * Use settings.local.php to override variables on secondary (staging,
