Skip to content

Commit 97371c3

Browse files
authored
Merge pull request #3752 from JulianFlesch/issues/3735-check-docker
Fixe Issues/3735: Check for docker and docker daemon and fail before download
2 parents e15bf4e + 3e78524 commit 97371c3

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

nf_core/pipelines/download/docker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ def check_and_set_implementation(self) -> None:
7777
"""
7878
Check if Docker is installed and set the implementation.
7979
"""
80-
if not shutil.which("docker"):
80+
docker_binary = shutil.which("docker")
81+
if not docker_binary:
8182
raise OSError("Docker is needed to pull images, but it is not installed or not in $PATH")
83+
84+
try:
85+
nf_core.utils.run_cmd(docker_binary, "info")
86+
except RuntimeError:
87+
raise OSError(
88+
"Docker daemon is required to pull images, but it is not running or unavailable to the docker client"
89+
)
90+
8291
self.implementation = "docker"
8392

8493
def gather_registries(self, workflow_directory: Path) -> set[str]:

nf_core/pipelines/download/download.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -494,26 +494,29 @@ def setup_container_fetcher(self) -> None:
494494
Create the appropriate ContainerFetcher object
495495
"""
496496
assert self.outdir is not None # mypy
497-
if self.container_system == "singularity":
498-
self.container_fetcher = SingularityFetcher(
499-
outdir=self.outdir,
500-
container_library=self.container_library,
501-
registry_set=self.registry_set,
502-
container_cache_utilisation=self.container_cache_utilisation,
503-
container_cache_index=self.container_cache_index,
504-
parallel=self.parallel,
505-
hide_progress=self.hide_progress,
506-
)
507-
elif self.container_system == "docker":
508-
self.container_fetcher = DockerFetcher(
509-
outdir=self.outdir,
510-
registry_set=self.registry_set,
511-
container_library=self.container_library,
512-
parallel=self.parallel,
513-
hide_progress=self.hide_progress,
514-
)
515-
else:
516-
self.container_fetcher = None
497+
try:
498+
if self.container_system == "singularity":
499+
self.container_fetcher = SingularityFetcher(
500+
outdir=self.outdir,
501+
container_library=self.container_library,
502+
registry_set=self.registry_set,
503+
container_cache_utilisation=self.container_cache_utilisation,
504+
container_cache_index=self.container_cache_index,
505+
parallel=self.parallel,
506+
hide_progress=self.hide_progress,
507+
)
508+
elif self.container_system == "docker":
509+
self.container_fetcher = DockerFetcher(
510+
outdir=self.outdir,
511+
registry_set=self.registry_set,
512+
container_library=self.container_library,
513+
parallel=self.parallel,
514+
hide_progress=self.hide_progress,
515+
)
516+
else:
517+
self.container_fetcher = None
518+
except OSError as e:
519+
raise DownloadError(e)
517520

518521
def prompt_use_singularity(self, fail_message: str) -> None:
519522
use_singularity = questionary.confirm(

0 commit comments

Comments
 (0)