Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix: read docker status on Window correctly

Vanalite0ec403582422
diff --git a/src-tauri/src/core/openclaw/sandbox_docker.rs b/src-tauri/src/core/openclaw/sandbox_docker.rs
index 62840d209..54e00ea89 100644
--- a/src-tauri/src/core/openclaw/sandbox_docker.rs
+++ b/src-tauri/src/core/openclaw/sandbox_docker.rs
@@ -77,48 +77,60 @@ impl DockerSandbox {
}
async fn get_client() -> Result<bollard::Docker, String> {
- if std::env::var("DOCKER_HOST").is_ok() {
+ // Windows: Docker Desktop uses a named pipe (//./pipe/docker_engine).
+ // connect_with_local_defaults() handles this and DOCKER_HOST.
+ #[cfg(target_os = "windows")]
+ {
return bollard::Docker::connect_with_local_defaults()
.map_err(|e| format!("Failed to connect to Docker: {}", e));
}
- let mut candidates: Vec<String> = vec![
- "/var/run/docker.sock".to_string(),
- ];
+ // macOS/Linux: try DOCKER_HOST, then probe known socket paths.
+ #[cfg(not(target_os = "windows"))]
+ {
+ if std::env::var("DOCKER_HOST").is_ok() {
+ return bollard::Docker::connect_with_local_defaults()
+ .map_err(|e| format!("Failed to connect to Docker: {}", e));
+ }
- if let Ok(home) = std::env::var("HOME") {
- // Docker Desktop on macOS/Linux
- candidates.push(format!("{}/.docker/run/docker.sock", home));
- }
+ let mut candidates: Vec<String> = vec![
+ "/var/run/docker.sock".to_string(),
+ ];
- #[cfg(target_os = "linux")]
- {
- let uid = unsafe { libc::getuid() };
- // Rootless Docker
- candidates.push(format!("/run/user/{}/docker.sock", uid));
- }
+ if let Ok(home) = std::env::var("HOME") {
+ candidates.push(format!("{}/.docker/run/docker.sock", home));
+ }
- for socket_path in &candidates {
- if !std::path::Path::new(socket_path).exists() {
- continue;
+ #[cfg(target_os = "linux")]
+ {
+ let uid = unsafe { libc::getuid() };
+ candidates.push(format!("/run/user/{}/docker.sock", uid));
}
- let uri = format!("unix://{}", socket_path);
- match bollard::Docker::connect_with_socket(
- &uri,
- 120,
- &bollard::API_DEFAULT_VERSION,
- ) {
- Ok(client) => {
- log::info!("DockerSandbox: connected via {}", socket_path);
- return Ok(client);
+
+ for socket_path in &candidates {
+ if !std::path::Path::new(socket_path).exists() {
+ continue;
}
- Err(e) => {
- log::info!("DockerSandbox: socket {} found but connect failed: {}", socket_path, e);
+ let uri = format!("unix://{}", socket_path);
+ match bollard::Docker::connect_with_socket(
+ &uri,
+ 120,
+ &bollard::API_DEFAULT_VERSION,
+ ) {
+ Ok(client) => {
+ log::info!("DockerSandbox: connected via {}", socket_path);
+ return Ok(client);
+ }
+ Err(e) => {
+ log::info!("DockerSandbox: socket {} found but connect failed: {}", socket_path, e);
+ }
}
}
- }
- Err("Failed to connect to Docker: no working socket found".to_string())
+ // Fallback for non-standard socket locations (Colima, Rancher Desktop, etc.)
+ bollard::Docker::connect_with_local_defaults()
+ .map_err(|_| "Failed to connect to Docker: no working socket found".to_string())
+ }
}
/// Check if the jan-openclaw container already exists (running or stopped).