From 2600f5e1fea714705f9726e2dc738b927d97f196 Mon Sep 17 00:00:00 2001 From: tbro Date: Wed, 28 Feb 2024 14:13:32 -0600 Subject: [PATCH 1/2] Cleanup docker containers on termination The `--rm` switch tells docker to cleanup containers on termination. Without this an exlicit `remove` is required after `stop` to clean up the container and a `prune` to remove arbitarary volumes left behind. While these are not difficult actions to perform, we are often unaware that we need to do them. I've also changed `kill` to `stop` because `stop` in the drop fn because `stop` attempts to shutdown the container gracefully. --- src/data_source/storage/sql.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/data_source/storage/sql.rs b/src/data_source/storage/sql.rs index 189bcf9dc..32d1dea4b 100644 --- a/src/data_source/storage/sql.rs +++ b/src/data_source/storage/sql.rs @@ -1450,6 +1450,7 @@ pub mod testing { let output = Command::new("docker") .arg("run") + .arg("--rm") .arg("-d") .args(["-p", &format!("{port}:5432")]) .args(["-e", "POSTGRES_PASSWORD=password"]) @@ -1520,7 +1521,7 @@ pub mod testing { impl Drop for TmpDb { fn drop(&mut self) { let output = Command::new("docker") - .args(["kill", self.container_id.as_str()]) + .args(["stop", self.container_id.as_str()]) .output() .unwrap(); if !output.status.success() { From 9a65b5043d0743cea334e01c294c49a8a5210bd5 Mon Sep 17 00:00:00 2001 From: tbro Date: Wed, 28 Feb 2024 15:27:00 -0600 Subject: [PATCH 2/2] avoid explict `rm` Because docker is now doing this --- src/data_source/storage/sql.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/data_source/storage/sql.rs b/src/data_source/storage/sql.rs index 32d1dea4b..99a38d811 100644 --- a/src/data_source/storage/sql.rs +++ b/src/data_source/storage/sql.rs @@ -1531,18 +1531,6 @@ pub mod testing { str::from_utf8(&output.stderr).unwrap() ); } - - let output = Command::new("docker") - .args(["rm", self.container_id.as_str()]) - .output() - .unwrap(); - if !output.status.success() { - tracing::error!( - "error removing postgres docker {}: {}", - self.container_id, - str::from_utf8(&output.stderr).unwrap() - ); - } } } }