Skip to content

Commit

Permalink
Warn users if the minimum version of Docker Desktop is not met
Browse files Browse the repository at this point in the history
This only happens on Windows and macOS.

Fixes #693
  • Loading branch information
almet committed Nov 28, 2024
1 parent c899886 commit 90c2e85
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dangerzone/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ def check_state(self) -> None:
error: Optional[str] = None

try:
is_available, version = self.dangerzone.isolation_provider.check_runtime_version()
if not is_available:
error = f"Your Docker version is too old ({version})."
print(error)
self.dangerzone.isolation_provider.is_runtime_available()
except NoContainerTechException as e:
log.error(str(e))
Expand Down
26 changes: 25 additions & 1 deletion dangerzone/isolation_provider/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from .base import IsolationProvider, terminate_process_group

TIMEOUT_KILL = 5 # Timeout in seconds until the kill command returns.

MINIMUM_DOCKER_VERSION = {
"Darwin": "4.35.1",
"Windows": "4.35.1",
}

# Define startupinfo for subprocesses
if platform.system() == "Windows":
Expand Down Expand Up @@ -197,10 +200,31 @@ def install() -> bool:
log.info("Container image installed")
return True

@staticmethod
def check_runtime_version() -> Tuple[bool, str]:
# On windows and darwin, check that the minimum version is met
if platform.system() != "Linux":
with subprocess.Popen(
["docker", "version", "--format", "'{{.Server.Platform.Name}}'"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
startupinfo=get_subprocess_startupinfo(),
) as p:
stdout, stderr = p.communicate()
if p.returncode != 0:
raise NotAvailableContainerTechException("docker", stderr.decode())
# The output is like "Docker Desktop 4.35.1 (173168)"
version = stdout.replace("Docker Desktop", "").split()[0]

if version < MINIMUM_DOCKER_VERSION[platform.system()]:
return False, version
return True, ""

@staticmethod
def is_runtime_available() -> bool:
container_runtime = Container.get_runtime()
runtime_name = Container.get_runtime_name()

# Can we run `docker/podman image ls` without an error
with subprocess.Popen(
[container_runtime, "image", "ls"],
Expand Down

0 comments on commit 90c2e85

Please sign in to comment.