pub struct DockerService { /* private fields */ }Expand description
Docker service for managing containers and Docker Compose
§Examples
use mecha10_cli::services::DockerService;
let service = DockerService::new();
// Check if Docker is available
service.check_installation()?;
// Start services with Docker Compose
service.compose_up(true).await?;
// Check container status
let running = service.is_container_running("mecha10-redis").await?;Implementations§
Source§impl DockerService
impl DockerService
Sourcepub fn with_compose_file(compose_file: impl Into<String>) -> Self
pub fn with_compose_file(compose_file: impl Into<String>) -> Self
Create a Docker service with a custom compose file path
§Arguments
compose_file- Path to docker-compose.yml
Sourcepub fn check_installation(&self) -> Result<DockerInfo>
pub fn check_installation(&self) -> Result<DockerInfo>
Check if Docker is installed and accessible
§Errors
Returns an error if Docker is not found or not executable.
Sourcepub fn check_daemon(&self) -> Result<()>
pub fn check_daemon(&self) -> Result<()>
Check if Docker daemon is running
§Errors
Returns an error if the daemon is not running or unreachable.
Sourcepub fn compose_build(&self, service: Option<&str>) -> Result<()>
pub fn compose_build(&self, service: Option<&str>) -> Result<()>
Build Docker images using Docker Compose
§Arguments
service- Optional service name to build (builds all if None)
Sourcepub async fn compose_up(&self, detach: bool) -> Result<()>
pub async fn compose_up(&self, detach: bool) -> Result<()>
Sourcepub async fn compose_up_service(
&self,
service: &str,
detach: bool,
) -> Result<()>
pub async fn compose_up_service( &self, service: &str, detach: bool, ) -> Result<()>
Start a specific service using Docker Compose
§Arguments
service- Service name to startdetach- Run in detached mode
Sourcepub async fn compose_run_service(
&self,
service: &str,
detach: bool,
service_ports: bool,
command_args: &[String],
) -> Result<()>
pub async fn compose_run_service( &self, service: &str, detach: bool, service_ports: bool, command_args: &[String], ) -> Result<()>
Run a one-off command in a service container
Uses docker compose run to start a service with custom command arguments.
§Arguments
service- Service name to rundetach- Run in detached modeservice_ports- Publish service ports (useful for detached mode)command_args- Additional arguments to pass to the container’s entrypoint
Sourcepub async fn compose_stop(&self, service: Option<&str>) -> Result<()>
pub async fn compose_stop(&self, service: Option<&str>) -> Result<()>
Stop services using Docker Compose
§Arguments
service- Optional service name to stop (stops all if None)
Sourcepub async fn compose_down(&self) -> Result<()>
pub async fn compose_down(&self) -> Result<()>
Stop and remove services using Docker Compose
Sourcepub async fn compose_restart(&self, service: Option<&str>) -> Result<()>
pub async fn compose_restart(&self, service: Option<&str>) -> Result<()>
Restart services using Docker Compose
§Arguments
service- Optional service name to restart (restarts all if None)
Sourcepub fn compose_logs(
&self,
service: Option<&str>,
follow: bool,
tail: Option<usize>,
) -> Result<()>
pub fn compose_logs( &self, service: Option<&str>, follow: bool, tail: Option<usize>, ) -> Result<()>
Get logs from Docker Compose services
§Arguments
service- Optional service name (all services if None)follow- Follow log outputtail- Number of lines to show from the end
Sourcepub async fn is_container_running(&self, container_name: &str) -> Result<bool>
pub async fn is_container_running(&self, container_name: &str) -> Result<bool>
Sourcepub async fn list_containers(&self) -> Result<Vec<ContainerInfo>>
pub async fn list_containers(&self) -> Result<Vec<ContainerInfo>>
List running containers
Sourcepub fn compose_file_exists(&self, path: Option<&Path>) -> bool
pub fn compose_file_exists(&self, path: Option<&Path>) -> bool
Sourcepub async fn wait_for_healthy(
&self,
container_name: &str,
timeout: Duration,
) -> Result<()>
pub async fn wait_for_healthy( &self, container_name: &str, timeout: Duration, ) -> Result<()>
Wait for a service to be healthy
§Arguments
container_name- Name of the containertimeout- Maximum time to wait
Sourcepub async fn start_project_services(
&self,
services: &[String],
project_name: &str,
) -> Result<bool>
pub async fn start_project_services( &self, services: &[String], project_name: &str, ) -> Result<bool>
Start project services for development mode
This is a convenience method that:
- Checks if services are already running
- Starts only the services that aren’t running
- Waits for them to be healthy
§Arguments
services- List of service names to startproject_name- Project name for container naming
§Returns
Returns Ok(true) if services were started, Ok(false) if already running
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DockerService
impl RefUnwindSafe for DockerService
impl Send for DockerService
impl Sync for DockerService
impl Unpin for DockerService
impl UnwindSafe for DockerService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more