diff --git a/cmd/cleanup.go b/cmd/cleanup.go index ff02d53..7c11111 100644 --- a/cmd/cleanup.go +++ b/cmd/cleanup.go @@ -23,13 +23,12 @@ func getIDs(dockerOutput []byte) []string { var result []string outputArray := strings.Split(string(dockerOutput), "\n") - for _, entry := range outputArray { - // Each container in the Docker Compose stack will have the name of the directory - if strings.Contains(entry, otelConfigDirName) { - fields := strings.Fields(entry) - if len(fields) > 0 { - result = append(result, fields[0]) - } + // skip the first line of the output, because it is the table header row + // docker ps does not support hiding column headers + for _, entry := range outputArray[1:] { + fields := strings.Fields(entry) + if len(fields) > 0 { + result = append(result, fields[0]) } } @@ -42,8 +41,7 @@ func cleanUp() error { } fmt.Println("Stopping Spin OTel Docker containers...") - - getContainers := exec.Command("docker", "ps") + getContainers := exec.Command("docker", "ps", fmt.Sprintf("--filter=name=%s*", otelConfigDirName), "--format=table") dockerPsOutput, err := getContainers.CombinedOutput() if err != nil { fmt.Println(string(dockerPsOutput))