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,26 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// DockerInspectContainer devuelve los detalles completos de un contenedor como JSON genérico.
|
||||
func DockerInspectContainer(nameOrID string) (map[string]any, error) {
|
||||
out, err := exec.Command("docker", "inspect", nameOrID).Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("docker inspect %s: %w", nameOrID, err)
|
||||
}
|
||||
|
||||
var result []map[string]any
|
||||
if err := json.Unmarshal(out, &result); err != nil {
|
||||
return nil, fmt.Errorf("parsing inspect output: %w", err)
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return nil, fmt.Errorf("container %s not found", nameOrID)
|
||||
}
|
||||
|
||||
return result[0], nil
|
||||
}
|
||||
Reference in New Issue
Block a user