DockerService

Struct DockerService 

Source
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

Source

pub fn new() -> Self

Create a new Docker service

Source

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
Source

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.

Source

pub fn check_daemon(&self) -> Result<()>

Check if Docker daemon is running

§Errors

Returns an error if the daemon is not running or unreachable.

Source

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)
Source

pub async fn compose_up(&self, detach: bool) -> Result<()>

Start services using Docker Compose

§Arguments
  • detach - Run in detached mode
Source

pub async fn compose_up_service( &self, service: &str, detach: bool, ) -> Result<()>

Start a specific service using Docker Compose

§Arguments
  • service - Service name to start
  • detach - Run in detached mode
Source

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 run
  • detach - Run in detached mode
  • service_ports - Publish service ports (useful for detached mode)
  • command_args - Additional arguments to pass to the container’s entrypoint
Source

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)
Source

pub async fn compose_down(&self) -> Result<()>

Stop and remove services using Docker Compose

Source

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)
Source

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 output
  • tail - Number of lines to show from the end
Source

pub async fn is_container_running(&self, container_name: &str) -> Result<bool>

Check if a container is running

§Arguments
  • container_name - Name or ID of the container
Source

pub async fn list_containers(&self) -> Result<Vec<ContainerInfo>>

List running containers

Source

pub fn compose_file_exists(&self, path: Option<&Path>) -> bool

Check if docker-compose.yml exists

§Arguments
  • path - Path to check (defaults to current directory)
Source

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 container
  • timeout - Maximum time to wait
Source

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:

  1. Checks if services are already running
  2. Starts only the services that aren’t running
  3. Waits for them to be healthy
§Arguments
  • services - List of service names to start
  • project_name - Project name for container naming
§Returns

Returns Ok(true) if services were started, Ok(false) if already running

Trait Implementations§

Source§

impl Default for DockerService

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more