pub struct Pyo3ComposeProject { /* private fields */ }Expand description
Manages a Docker Compose project for orchestrating multi-container deployments.
A ComposeProject represents a running or potential deployment of a Compose file. It provides methods to bring services up (create and start) or down (stop and remove).
Example: >>> docker = Docker() >>> compose = parse_compose_file(“docker-compose.yml”) >>> project = ComposeProject(docker, compose, “myproject”) >>> project.up() # Create networks, volumes, and start containers >>> project.down() # Stop and remove containers
Implementations§
Source§impl Pyo3ComposeProject
impl Pyo3ComposeProject
Sourcepub fn new(
docker: Pyo3Docker,
compose: Pyo3ComposeFile,
project_name: &str,
) -> Self
pub fn new( docker: Pyo3Docker, compose: Pyo3ComposeFile, project_name: &str, ) -> Self
Create a new ComposeProject.
Args: docker: Docker client instance compose: Parsed ComposeFile instance project_name: Name for this project (used as prefix for resources)
Returns: ComposeProject: Project instance ready for up/down operations
Sourcepub fn get_project_name(&self) -> String
pub fn get_project_name(&self) -> String
Get the project name.
Returns: str: Project name
Sourcepub fn up(&self, py: Python<'_>, detach: Option<bool>) -> PyResult<Py<PyAny>>
pub fn up(&self, py: Python<'_>, detach: Option<bool>) -> PyResult<Py<PyAny>>
Bring up the compose project.
Creates networks, volumes, and containers defined in the compose file, then starts the containers.
Args: detach: Run containers in the background (default: True)
Returns: dict: Results including created network IDs, volume names, and container IDs
Raises: RuntimeError: If any operation fails
Sourcepub fn down(
&self,
py: Python<'_>,
remove_volumes: Option<bool>,
remove_networks: Option<bool>,
timeout: Option<u64>,
) -> PyResult<Py<PyAny>>
pub fn down( &self, py: Python<'_>, remove_volumes: Option<bool>, remove_networks: Option<bool>, timeout: Option<u64>, ) -> PyResult<Py<PyAny>>
Bring down the compose project.
Stops and removes containers, and optionally removes networks and volumes.
Args: remove_volumes: Also remove named volumes (default: False) remove_networks: Also remove networks (default: True) timeout: Timeout in seconds for stopping containers (default: 10)
Returns: dict: Results including stopped/removed container IDs, network IDs, volume names
Raises: RuntimeError: If any operation fails
Sourcepub fn ps(&self) -> PyResult<Vec<String>>
pub fn ps(&self) -> PyResult<Vec<String>>
List containers for this project.
Returns: liststr: List of container IDs belonging to this project
Sourcepub fn start(&self) -> PyResult<Vec<String>>
pub fn start(&self) -> PyResult<Vec<String>>
Start all stopped containers in the project.
Starts containers that were previously stopped without recreating them.
Returns: liststr: List of container IDs that were started
Raises: RuntimeError: If any container fails to start
Sourcepub fn stop(&self, timeout: Option<u64>) -> PyResult<Vec<String>>
pub fn stop(&self, timeout: Option<u64>) -> PyResult<Vec<String>>
Stop all running containers in the project.
Stops containers without removing them.
Args: timeout: Timeout in seconds to wait for containers to stop (default: 10)
Returns: liststr: List of container IDs that were stopped
Raises: RuntimeError: If any container fails to stop
Sourcepub fn restart(&self, timeout: Option<u64>) -> PyResult<Vec<String>>
pub fn restart(&self, timeout: Option<u64>) -> PyResult<Vec<String>>
Restart all containers in the project.
Restarts all containers without recreating them.
Args: timeout: Timeout in seconds to wait for containers to stop before restart (default: 10)
Returns: liststr: List of container IDs that were restarted
Raises: RuntimeError: If any container fails to restart
Sourcepub fn pause(&self) -> PyResult<Vec<String>>
pub fn pause(&self) -> PyResult<Vec<String>>
Pause all running containers in the project.
Pauses all processes within the containers.
Returns: liststr: List of container IDs that were paused
Raises: RuntimeError: If any container fails to pause
Sourcepub fn unpause(&self) -> PyResult<Vec<String>>
pub fn unpause(&self) -> PyResult<Vec<String>>
Unpause all paused containers in the project.
Resumes all processes within the containers.
Returns: liststr: List of container IDs that were unpaused
Raises: RuntimeError: If any container fails to unpause
Sourcepub fn pull(&self) -> PyResult<Vec<String>>
pub fn pull(&self) -> PyResult<Vec<String>>
Pull images for all services in the project.
Pulls the images specified in the compose file for all services that
have an image field defined.
Returns: liststr: List of images that were pulled
Raises: RuntimeError: If any image fails to pull
Sourcepub fn build(
&self,
no_cache: Option<bool>,
pull: Option<bool>,
) -> PyResult<Vec<String>>
pub fn build( &self, no_cache: Option<bool>, pull: Option<bool>, ) -> PyResult<Vec<String>>
Build images for all services in the project that have a build config.
Builds images for services that have a build field defined in the compose file.
Services with only an image field are skipped.
Args: no_cache: Do not use cache when building (default: False) pull: Always pull newer versions of base images (default: False)
Returns: liststr: List of services that were built
Raises: RuntimeError: If any build fails
Sourcepub fn push(&self) -> PyResult<Vec<String>>
pub fn push(&self) -> PyResult<Vec<String>>
Push images for all services in the project.
Pushes images for services that have an image field defined to their registry.
Returns: liststr: List of images that were pushed
Raises: RuntimeError: If any image fails to push
Sourcepub fn ps_detailed(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
pub fn ps_detailed(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
Get detailed information about containers in the project.
Returns detailed information about each container including ID, name, state, service name, and image.
Returns: list[dict]: List of container info dicts with keys: - id: Container ID - name: Container name - service: Service name from compose file - state: Container state (running, stopped, etc.) - status: Container status message - image: Image used by the container
Raises: RuntimeError: If container information cannot be retrieved
Sourcepub fn logs(
&self,
py: Python<'_>,
service: Option<&str>,
tail: Option<usize>,
timestamps: Option<bool>,
) -> PyResult<Py<PyAny>>
pub fn logs( &self, py: Python<'_>, service: Option<&str>, tail: Option<usize>, timestamps: Option<bool>, ) -> PyResult<Py<PyAny>>
Get logs from all containers in the project.
Collects logs from all containers belonging to this project.
Args: service: Only get logs from this service (optional) tail: Number of lines to show from the end of logs (optional) timestamps: Include timestamps in output (default: False)
Returns: dict[str, str]: Mapping of container ID to its logs
Raises: RuntimeError: If logs cannot be retrieved
Sourcepub fn config(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
pub fn config(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
Get the compose configuration as a dictionary.
Returns the parsed compose file configuration, useful for inspecting the services, networks, and volumes defined in the project.
Returns: dict: The compose file configuration
Sourcepub fn top(&self, py: Python<'_>, ps_args: Option<&str>) -> PyResult<Py<PyAny>>
pub fn top(&self, py: Python<'_>, ps_args: Option<&str>) -> PyResult<Py<PyAny>>
Get running processes from all containers in the project.
Returns process information from all running containers in the project.
Args: ps_args: Arguments to pass to ps command (e.g., “aux”)
Returns: dict[str, dict]: Mapping of container ID to its process info
Raises: RuntimeError: If process information cannot be retrieved
Sourcepub fn exec(
&self,
service: &str,
command: Vec<String>,
user: Option<&str>,
workdir: Option<&str>,
env: Option<Vec<String>>,
privileged: Option<bool>,
tty: Option<bool>,
) -> PyResult<String>
pub fn exec( &self, service: &str, command: Vec<String>, user: Option<&str>, workdir: Option<&str>, env: Option<Vec<String>>, privileged: Option<bool>, tty: Option<bool>, ) -> PyResult<String>
Execute a command in a running service container.
Runs a command in the first running container of the specified service,
similar to docker-compose exec.
Args: service: Name of the service to execute the command in command: Command to execute as a list (e.g., [“ls”, “-la”]) user: User to run the command as (optional) workdir: Working directory inside the container (optional) env: Environment variables as a list (e.g., [“VAR=value”]) (optional) privileged: Give extended privileges to the command (default: False) tty: Allocate a pseudo-TTY (default: False)
Returns: str: Output from the executed command
Raises: RuntimeError: If no running container is found for the service RuntimeError: If command execution fails
Sourcepub fn run(
&self,
py: Python<'_>,
service: &str,
command: Option<Vec<String>>,
user: Option<&str>,
workdir: Option<&str>,
env: Option<Vec<String>>,
rm: Option<bool>,
detach: Option<bool>,
) -> PyResult<Py<PyAny>>
pub fn run( &self, py: Python<'_>, service: &str, command: Option<Vec<String>>, user: Option<&str>, workdir: Option<&str>, env: Option<Vec<String>>, rm: Option<bool>, detach: Option<bool>, ) -> PyResult<Py<PyAny>>
Run a one-off command in a new container for a service.
Creates a new container based on the service configuration, runs the
specified command, and optionally removes the container afterward.
Similar to docker-compose run.
Args: service: Name of the service to run command: Command to execute as a list (e.g., [“python”, “script.py”]). If not provided, uses the service’s default command. user: User to run the command as (optional) workdir: Working directory inside the container (optional) env: Additional environment variables as a list (e.g., [“VAR=value”]) rm: Remove the container after exit (default: True) detach: Run container in the background (default: False)
Returns: dict: Result containing container_id and output (if not detached)
Raises: RuntimeError: If the service is not found in the compose file RuntimeError: If container creation or execution fails
Trait Implementations§
Source§impl Debug for Pyo3ComposeProject
impl Debug for Pyo3ComposeProject
Source§impl<'py> IntoPyObject<'py> for Pyo3ComposeProject
impl<'py> IntoPyObject<'py> for Pyo3ComposeProject
Source§type Target = Pyo3ComposeProject
type Target = Pyo3ComposeProject
Source§type Output = Bound<'py, <Pyo3ComposeProject as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <Pyo3ComposeProject as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for Pyo3ComposeProject
impl PyClass for Pyo3ComposeProject
Source§impl PyClassImpl for Pyo3ComposeProject
impl PyClassImpl for Pyo3ComposeProject
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Manages a Docker Compose project for orchestrating multi-container deployments.
///
/// A ComposeProject represents a running or potential deployment of a Compose file.
/// It provides methods to bring services up (create and start) or down (stop and remove).
///
/// Example:
/// >>> docker = Docker()
/// >>> compose = parse_compose_file("docker-compose.yml")
/// >>> project = ComposeProject(docker, compose, "myproject")
/// >>> project.up() # Create networks, volumes, and start containers
/// >>> project.down() # Stop and remove containers
const RAW_DOC: &'static CStr = /// Manages a Docker Compose project for orchestrating multi-container deployments. /// /// A ComposeProject represents a running or potential deployment of a Compose file. /// It provides methods to bring services up (create and start) or down (stop and remove). /// /// Example: /// >>> docker = Docker() /// >>> compose = parse_compose_file("docker-compose.yml") /// >>> project = ComposeProject(docker, compose, "myproject") /// >>> project.up() # Create networks, volumes, and start containers /// >>> project.down() # Stop and remove containers
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<Pyo3ComposeProject>
type ThreadChecker = SendablePyClass<Pyo3ComposeProject>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for Pyo3ComposeProject
impl PyClassNewTextSignature for Pyo3ComposeProject
const TEXT_SIGNATURE: &'static str = "(docker, compose, project_name)"
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder Pyo3ComposeProject
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder Pyo3ComposeProject
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut Pyo3ComposeProject
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut Pyo3ComposeProject
Source§impl PyMethods<Pyo3ComposeProject> for PyClassImplCollector<Pyo3ComposeProject>
impl PyMethods<Pyo3ComposeProject> for PyClassImplCollector<Pyo3ComposeProject>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Pyo3ComposeProject
impl PyTypeInfo for Pyo3ComposeProject
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny for Pyo3ComposeProject
Auto Trait Implementations§
impl Freeze for Pyo3ComposeProject
impl !RefUnwindSafe for Pyo3ComposeProject
impl Send for Pyo3ComposeProject
impl Sync for Pyo3ComposeProject
impl Unpin for Pyo3ComposeProject
impl !UnwindSafe for Pyo3ComposeProject
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<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.