diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index 0e0ac5a93a..d147b14562 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -221,6 +221,9 @@ def _build_function_on_container(self, # pylint: disable=too-many-locals manifest_path, runtime): + if not self._container_manager.is_docker_reachable: + raise BuildError("Docker is unreachable. Docker needs to be running to build inside a container.") + # If we are printing debug logs in SAM CLI, the builder library should also print debug logs log_level = LOG.getEffectiveLevel() diff --git a/tests/unit/lib/build_module/test_app_builder.py b/tests/unit/lib/build_module/test_app_builder.py index 28bdb8298f..e0e769dbb5 100644 --- a/tests/unit/lib/build_module/test_app_builder.py +++ b/tests/unit/lib/build_module/test_app_builder.py @@ -309,6 +309,22 @@ def test_must_raise_on_unsupported_container(self, LambdaBuildContainerMock): self.assertEquals(str(ctx.exception), msg) self.container_manager.stop.assert_called_with(container_mock) + def test_must_raise_on_docker_not_running(self): + config = Mock() + + self.container_manager.is_docker_reachable = False + + with self.assertRaises(BuildError) as ctx: + self.builder._build_function_on_container(config, + "source_dir", + "artifacts_dir", + "scratch_dir", + "manifest_path", + "runtime") + + self.assertEquals(str(ctx.exception), + "Docker is unreachable. Docker needs to be running to build inside a container.") + class TestApplicationBuilder_parse_builder_response(TestCase):