Last active
August 14, 2025 18:43
-
-
Save nerdyslacker/dcfd93e201750064c8409d836f705ded to your computer and use it in GitHub Desktop.
Interactive Docker Container Exec (fzf/rofi)
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 | |
selected=$(docker ps --format '{{.ID}} {{.Names}}' | fzf --prompt="Select container: ") | |
[ -z "$selected" ] && echo "No container selected." && exit 1 | |
container_id=$(echo "$selected" | awk '{print $1}') | |
command_exists() { | |
docker exec "$container_id" sh -c "command -v $1 >/dev/null 2>&1" | |
} | |
if command_exists bash; then | |
shell="bash" | |
elif command_exists sh; then | |
shell="sh" | |
else | |
echo "No bash or sh found in container $container_id" | |
exit 1 | |
fi | |
docker exec -it "$container_id" "$shell" |
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 | |
TERMINAL="xfce4-terminal" # Change to your preferred terminal | |
containers=$(docker ps --format '{{.ID}} {{.Names}}') | |
selected=$(echo "$containers" | rofi -dmenu -p "Select container:") | |
[ -z "$selected" ] && echo "No container selected." && exit 1 | |
container_id=$(echo "$selected" | awk '{print $1}') | |
command_exists() { | |
docker exec "$container_id" sh -c "command -v $1 >/dev/null 2>&1" | |
} | |
if command_exists bash; then | |
shell="bash" | |
elif command_exists sh; then | |
shell="sh" | |
else | |
echo "No bash or sh found in container $container_id" | |
exit 1 | |
fi | |
$TERMINAL -e "docker exec -it \"$container_id\" \"$shell\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment