mirror of
https://github.com/bigbeartechworld/big-bear-scripts.git
synced 2026-07-30 17:16:15 -04:00
Add docker-exec-helper script
This commit is contained in:
5
docker-exec-helper/README.md
Normal file
5
docker-exec-helper/README.md
Normal 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
26
docker-exec-helper/run.sh
Normal 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
|
||||
Reference in New Issue
Block a user