diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index d722d6b..0bf3187 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -557,12 +557,12 @@ public function discoverServiceProviders() {
         }
       }
     }
-    if ($container_yamls = Settings::get('container_yamls')) {
-      $this->serviceYamls['site'] = $container_yamls;
+    $container_yamls = Settings::get('container_yamls');
+    if (is_array($container_yamls)) {
+      $this->serviceYamls['site'] = array_filter($container_yamls, 'file_exists');
     }
-    $site_services_yml = $this->getSitePath() . '/services.yml';
-    if (file_exists($site_services_yml) && is_readable($site_services_yml)) {
-      $this->serviceYamls['site'][] = $site_services_yml;
+    else {
+      throw new \Exception('"Please add $settings["container_yamls"][] = __DIR__ . "/services.yml"; to settings.php');
     }
   }
 
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/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php b/core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php
new file mode 100644
index 0000000..86d58c3
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/DrupalKernel/DiscoverServiceProvidersTest.php
@@ -0,0 +1,47 @@
+<?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);
+  }
+
+}
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,
