Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions libs/python/computer/computer/providers/docker/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,20 @@ async def run_vm(
logger.info(f"Container {name} is already running")
return existing_vm
elif existing_vm["status"] in ["stopped", "paused"]:
# Start existing container
logger.info(f"Starting existing container {name}")
start_cmd = ["docker", "start", name]
result = subprocess.run(start_cmd, capture_output=True, text=True, check=True)
if self.ephemeral:
# Delete existing container
logger.info(f"Deleting existing container {name}")
delete_cmd = ["docker", "rm", name]
result = subprocess.run(delete_cmd, capture_output=True, text=True, check=True)
else:
# Start existing container
logger.info(f"Starting existing container {name}")
start_cmd = ["docker", "start", name]
result = subprocess.run(start_cmd, capture_output=True, text=True, check=True)

# Wait for container to be ready
await self._wait_for_container_ready(name)
return await self.get_vm(name, storage)
# Wait for container to be ready
await self._wait_for_container_ready(name)
return await self.get_vm(name, storage)

# Use provided image or default
docker_image = image if image != "default" else self.image
Expand Down Expand Up @@ -307,6 +313,20 @@ async def run_vm(
cmd.extend(["-e", "VNC_PW=password"]) # Set VNC password
cmd.extend(["-e", "VNCOPTIONS=-disableBasicAuth"]) # Disable VNC basic auth

# Apply display resolution if provided (e.g., "1024x768")
display_resolution = run_opts.get("display")
if (
isinstance(display_resolution, dict)
and "width" in display_resolution
and "height" in display_resolution
):
cmd.extend(
[
"-e",
f"VNC_RESOLUTION={display_resolution['width']}x{display_resolution['height']}",
]
)

# Add the image
cmd.append(docker_image)

Expand Down Expand Up @@ -388,6 +408,11 @@ async def stop_vm(self, name: str, storage: Optional[str] = None) -> Dict[str, A

logger.info(f"Container {name} stopped successfully")

# Delete container if ephemeral=True
if self.ephemeral:
cmd = ["docker", "rm", name]
result = subprocess.run(cmd, capture_output=True, text=True, check=True)

return {
"name": name,
"status": "stopped",
Expand Down