Skip to content

Commit

Permalink
- improve: docker status
Browse files Browse the repository at this point in the history
  • Loading branch information
agallardol committed Nov 15, 2024
1 parent ec1908b commit 4fcf72d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions libs/shinkai-tools-runner/src/tools/container_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use std::process::Command;

#[derive(Debug, PartialEq)]
pub enum DockerStatus {
NotInstalled,
NotRunning,
Running,
}

/// Checks if Docker is available on the system by attempting to run 'docker info' command.
/// This function verifies both that Docker is installed and that the Docker daemon is running.
///
Expand Down Expand Up @@ -31,15 +38,17 @@ use std::process::Command;
/// println!("docker is not available - check installation and permissions");
/// }
/// ```
pub fn is_docker_available() -> bool {
// Try to run 'docker info' command
pub fn is_docker_available() -> DockerStatus {
let docker_check = Command::new("docker").arg("info").output();

match docker_check {
Ok(output) => {
// Check if command was successful (exit code 0)
output.status.success()
if output.status.success() {
DockerStatus::Running
} else {
DockerStatus::NotRunning
}
}
Err(_) => false, // Docker command not found or failed to execute
Err(_) => DockerStatus::NotInstalled,
}
}

0 comments on commit 4fcf72d

Please sign in to comment.