I'm writing this naive code in golang to ask docker to remove all container by force, but when running it, it always give me err: exit status 125
.
I'm extremely confused as it runs smoothly on my own cli.
func removeAllContainers() error {
// container ls -a -q | xargs docker container rm
_, err := exec.Command(
"docker",
"container",
"ls",
"-a",
"-q",
"|",
"xargs",
"docker",
"container",
"rm",
"-f",
).Output()
if err != nil {
return fmt.Errorf("cannot remove all containers: %v", err)
}
return nil
}
This error message is very uninformative -- we only know that the deamon is having some problem, but don't know what that problem is! I wonder if there's a way to get more detailed error message when running a docker command in golang.