From d1af2c7cac63eaadb54141c369f74f84eb85936a Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 11 Oct 2023 18:07:58 -0500 Subject: [PATCH] Add docker-exec-helper script --- docker-exec-helper/README.md | 5 +++++ docker-exec-helper/run.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 docker-exec-helper/README.md create mode 100644 docker-exec-helper/run.sh diff --git a/docker-exec-helper/README.md b/docker-exec-helper/README.md new file mode 100644 index 0000000..0f036e5 --- /dev/null +++ b/docker-exec-helper/README.md @@ -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)" +``` diff --git a/docker-exec-helper/run.sh b/docker-exec-helper/run.sh new file mode 100644 index 0000000..df51e8a --- /dev/null +++ b/docker-exec-helper/run.sh @@ -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