Skip to content

Instantly share code, notes, and snippets.

@nerdyslacker
Last active August 14, 2025 18:43
Show Gist options
  • Save nerdyslacker/dcfd93e201750064c8409d836f705ded to your computer and use it in GitHub Desktop.
Save nerdyslacker/dcfd93e201750064c8409d836f705ded to your computer and use it in GitHub Desktop.
Interactive Docker Container Exec (fzf/rofi)
#!/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"
#!/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