This commit is contained in:
2025-04-05 09:36:54 +02:00
parent 4c50d4b62c
commit 78db13d738
15 changed files with 1119 additions and 248 deletions

View File

@@ -7,6 +7,7 @@ use super::health_check_script::prepare_health_check_command;
impl Container {
/// Reset the container configuration to defaults while keeping the name and image
/// If the container exists, it will be stopped and removed.
///
/// # Returns
///
@@ -14,12 +15,22 @@ impl Container {
pub fn reset(mut self) -> Self {
let name = self.name;
let image = self.image.clone();
let container_id = self.container_id.clone();
// Create a new container with just the name, image, and container_id
// If container exists, stop and remove it
if let Some(container_id) = &self.container_id {
println!("Container exists. Stopping and removing container '{}'...", name);
// Try to stop the container
let _ = execute_nerdctl_command(&["stop", container_id]);
// Try to remove the container
let _ = execute_nerdctl_command(&["rm", container_id]);
}
// Create a new container with just the name and image, but no container_id
Self {
name,
container_id,
container_id: None, // Reset container_id to None since we removed the container
image,
config: std::collections::HashMap::new(),
ports: Vec::new(),