Fix Docker backend failures on macOS
Three issues prevented the Docker terminal backend from working: 1. `effective_image` was referenced but never defined — only the Modal backend sets this variable. Use `image` directly instead. 2. `--storage-opt size=N` is unsupported on Docker Desktop for Mac (requires overlay2 with xfs backing). Skip the flag on Darwin. 3. Docker requires absolute paths for `-w` (working directory) but the default cwd was `~`, which Docker does not expand. Default to `/root` and translate any `~` passed in from callers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cbde8548f4
commit
b6d7e222c1
1 changed files with 6 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ and optional filesystem persistence via `docker commit`/`docker create --image`.
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
@ -44,7 +45,7 @@ class DockerEnvironment(BaseEnvironment):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
image: str,
|
image: str,
|
||||||
cwd: str = "~",
|
cwd: str = "/root",
|
||||||
timeout: int = 60,
|
timeout: int = 60,
|
||||||
cpu: float = 0,
|
cpu: float = 0,
|
||||||
memory: int = 0,
|
memory: int = 0,
|
||||||
|
|
@ -53,6 +54,8 @@ class DockerEnvironment(BaseEnvironment):
|
||||||
task_id: str = "default",
|
task_id: str = "default",
|
||||||
network: bool = True,
|
network: bool = True,
|
||||||
):
|
):
|
||||||
|
if cwd == "~":
|
||||||
|
cwd = "/root"
|
||||||
super().__init__(cwd=cwd, timeout=timeout)
|
super().__init__(cwd=cwd, timeout=timeout)
|
||||||
self._base_image = image
|
self._base_image = image
|
||||||
self._persistent = persistent_filesystem
|
self._persistent = persistent_filesystem
|
||||||
|
|
@ -67,7 +70,7 @@ class DockerEnvironment(BaseEnvironment):
|
||||||
resource_args.extend(["--cpus", str(cpu)])
|
resource_args.extend(["--cpus", str(cpu)])
|
||||||
if memory > 0:
|
if memory > 0:
|
||||||
resource_args.extend(["--memory", f"{memory}m"])
|
resource_args.extend(["--memory", f"{memory}m"])
|
||||||
if disk > 0:
|
if disk > 0 and sys.platform != "darwin":
|
||||||
resource_args.extend(["--storage-opt", f"size={disk}m"])
|
resource_args.extend(["--storage-opt", f"size={disk}m"])
|
||||||
if not network:
|
if not network:
|
||||||
resource_args.append("--network=none")
|
resource_args.append("--network=none")
|
||||||
|
|
@ -102,7 +105,7 @@ class DockerEnvironment(BaseEnvironment):
|
||||||
all_run_args = list(_SECURITY_ARGS) + writable_args + resource_args
|
all_run_args = list(_SECURITY_ARGS) + writable_args + resource_args
|
||||||
|
|
||||||
self._inner = _Docker(
|
self._inner = _Docker(
|
||||||
image=effective_image, cwd=cwd, timeout=timeout,
|
image=image, cwd=cwd, timeout=timeout,
|
||||||
run_args=all_run_args,
|
run_args=all_run_args,
|
||||||
)
|
)
|
||||||
self._container_id = self._inner.container_id
|
self._container_id = self._inner.container_id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue