Add docker-exec-helper script

This commit is contained in:
Christopher
2023-10-11 18:07:58 -05:00
parent 900c46476e
commit d1af2c7cac
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
# Run command
```bash
bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/docker-exec-helper/run.sh)"
```

26
docker-exec-helper/run.sh Normal file
View File

@@ -0,0 +1,26 @@
#!/bin/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