0402e0fdbe
Funciones Docker: list/start/stop/remove containers, list/pull/remove images, inspect, logs, run. Tipos: ContainerInfo e ImageInfo. Pre-existentes en el dominio infra, ahora registrados.
24 lines
562 B
Go
24 lines
562 B
Go
package infra
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// DockerStopContainer detiene un contenedor Docker. timeoutSecs indica el tiempo de gracia antes de SIGKILL.
|
|
func DockerStopContainer(nameOrID string, timeoutSecs int) error {
|
|
args := []string{"stop"}
|
|
if timeoutSecs > 0 {
|
|
args = append(args, "-t", strconv.Itoa(timeoutSecs))
|
|
}
|
|
args = append(args, nameOrID)
|
|
|
|
out, err := exec.Command("docker", args...).CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("docker stop %s: %s", nameOrID, strings.TrimSpace(string(out)))
|
|
}
|
|
return nil
|
|
}
|