Files
big-bear-scripts/docker-exec-helper/run.sh
Christopher 222e6af258 🔧 refactor: Use #!/usr/bin/env bash in all shell scripts (#16)
This commit refactors all the shell scripts to use `#!/usr/bin/env bash` instead of `#!/bin/bash`. This change ensures that the scripts will run with the system's default Bash interpreter, even if it is not located at the standard `/bin/bash` path.
2024-10-23 13:32:15 -05:00

27 lines
844 B
Bash

#!/usr/bin/env bash
# List all running containers
containers=$(docker ps --format "{{.Names}}")
IFS=$'\n' read -rd '' -a containerArray <<< "$containers"
echo "Select a Docker container to exec into:"
counter=1
for container in "${containerArray[@]}"; do
echo "$counter. $container"
let counter++
done
# Get user's choice
read -p "Enter the number of the container: " choice
selectedContainer="${containerArray[$choice-1]}"
# Check if user wants additional arguments
read -p "Do you want to provide additional arguments? (e.g., -u www-data) [y/N]: " additionalArgsChoice
additionalArgs=""
if [[ $additionalArgsChoice == "y" || $additionalArgsChoice == "Y" ]]; then
read -p "Enter the additional arguments: " additionalArgs
fi
# Docker exec into the chosen container
docker exec -it $additionalArgs $selectedContainer /bin/bash