feat: 10 funciones infra Docker y 2 tipos — operaciones de contenedores e imagenes
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.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// DockerContainerLogs obtiene los logs de un contenedor. tail limita las últimas N líneas (0 = todas).
|
||||
func DockerContainerLogs(nameOrID string, tail int) (string, error) {
|
||||
args := []string{"logs"}
|
||||
if tail > 0 {
|
||||
args = append(args, "--tail", strconv.Itoa(tail))
|
||||
}
|
||||
args = append(args, nameOrID)
|
||||
|
||||
out, err := exec.Command("docker", args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("docker logs %s: %w", nameOrID, err)
|
||||
}
|
||||
|
||||
return string(out), nil
|
||||
}
|
||||
Reference in New Issue
Block a user