add explicit log message on failing Docker connection, see
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -611,8 +611,11 @@ class Repo2Docker(Application):
try:
docker_client = docker.APIClient(version="auto", **kwargs_from_env())
except DockerException as e:
- self.log.exception(e)
+ self.log.error(
+ "\nDocker client initialization error. Check if docker is running on the host.\n\n"
+ )
raise
+
# If the source to be executed is a directory, continue using the
# directory. In the case of a local directory, it is used as both the
# source and target. Reusing a local directory seems better than

MODIFY
tests/unit/test_app.py
tests/unit/test_app.py
@@ -8,6 +8,7 @@ import escapism
from repo2docker.app import Repo2Docker
from repo2docker.__main__ import make_r2d
+from repo2docker.utils import chdir
def test_find_image():
@@ -124,3 +125,24 @@ def test_root_not_allowed():
builds.return_value = []
app.build()
builds.assert_called_once()
+
+
+def test_dryrun_works_without_docker(tmpdir):
+ with chdir(tmpdir):
+ with patch.object(docker, "APIClient") as client:
+ client.side_effect = docker.errors.DockerException("Error: no Docker")
+ app = Repo2Docker(dry_run=True)
+ app.build()
+
+
+def test_error_log_without_docker(tmpdir, caplog):
+ with chdir(tmpdir):
+ with patch.object(docker, "APIClient") as client:
+ client.side_effect = docker.errors.DockerException("Error: no Docker")
+ app = Repo2Docker()
+
+ with pytest.raises(docker.errors.DockerException):
+ app.build()
+
+ captured = capsys.readouterr()
+ assert "Check if docker is running" in captured.err

MODIFY
tests/unit/test_subdir.py
tests/unit/test_subdir.py
@@ -33,7 +33,7 @@ def test_subdir_in_image_name():
assert escaped_dirname in app.output_image_spec
-def test_subdir_invalid(caplog):
+def test_subdir_invalid():
# test an error is raised when requesting a non existent subdir
app = Repo2Docker(repo=TEST_REPO, subdir="invalid-sub-dir")
app.initialize()

add explicit log message on failing Docker connection, see #774