Last active
April 19, 2026 15:41
-
-
Save horaciod/cbc195aa37048a45c7dc6150ee134b42 to your computer and use it in GitHub Desktop.
show composer.yaml and volumes using fzf and bash from dockers running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Función para obtener la ruta del YAML | |
| get_compose_path() { | |
| local target=$1 | |
| docker inspect --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}' "$target" 2>/dev/null | |
| } | |
| if [ -z "$1" ]; then | |
| # PREVIEW_CMD con colores ajustados para visibilidad | |
| PREVIEW_CMD="echo -e '\e[1;36m--- REDES ---\e[0m'; \ | |
| docker inspect {1} --format '{{range \$net, \$conf := .NetworkSettings.Networks}}- {{ \$net }} ({{ \$conf.IPAddress }}){{println}}{{end}}'; \ | |
| echo -e '\n\e[1;36m--- PUERTOS (Host -> Contenedor) ---\e[0m'; \ | |
| docker inspect {1} --format '{{range \$p, \$conf := .NetworkSettings.Ports}}{{range \$conf}}{{ .HostIp }}:{{ .HostPort }} -> {{ \$p }}{{println}}{{end}}{{else}}Sin puertos mapeados{{end}}'; \ | |
| echo -e '\n\e[1;36m--- VOLÚMENES ---\e[0m'; \ | |
| docker inspect {1} --format '{{range .Mounts}}- {{.Source}} -> {{.Destination}}{{println}}{{end}}'" | |
| SELECTION=$(docker ps --format "{{.Names}}" | fzf \ | |
| --height 80% \ | |
| --reverse \ | |
| --header "Contenedores activos | Enter para ver YAML" \ | |
| --preview "$PREVIEW_CMD" \ | |
| --preview-window=right:65%:wrap) | |
| if [ -z "$SELECTION" ]; then | |
| exit 0 | |
| fi | |
| CONTAINER_NAME=$SELECTION | |
| else | |
| CONTAINER_NAME=$1 | |
| fi | |
| COMPOSE_PATH=$(get_compose_path "$CONTAINER_NAME") | |
| if [ -z "$COMPOSE_PATH" ]; then | |
| echo -e "\n\033[1;31m[!] El contenedor '$CONTAINER_NAME' no tiene etiquetas de Docker Compose.\033[0m" | |
| exit 1 | |
| else | |
| # Separador en Cian para que se vea sí o sí | |
| SEPARATOR="\033[1;36m------------------------------------------------------------\033[0m" | |
| echo -e "\n\033[1;32m✔ Contenedor:\033[0m $CONTAINER_NAME" | |
| echo -e "\033[1;34m✔ Archivo YAML:\033[0m $COMPOSE_PATH" | |
| echo -e "\n$SEPARATOR" | |
| echo -e "\033[1;33mResumen de Red y Puertos:\033[0m" | |
| docker inspect --format 'Redes: {{range $net, $v := .NetworkSettings.Networks}}{{$net}} ({{$v.IPAddress}}) {{end}} | |
| Puertos: {{range $p, $conf := .NetworkSettings.Ports}}{{range $conf}}{{.HostIp}}:{{.HostPort}}->{{$p}} {{end}}{{end}}' "$CONTAINER_NAME" | |
| echo -e "$SEPARATOR\n" | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
instalar previamente fzf
salida ejemplo