Created
February 22, 2024 21:49
-
-
Save pancudaniel7/8e483dbd4b0af3b232fc981405380751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List running Docker containers | |
echo "Running Docker containers:" | |
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.ID}}" | nl -w2 -s': ' | |
# Ask the user to select a container | |
echo "Enter the number of the container you want to bash into:" | |
read container_number | |
# Get the container ID based on user selection | |
container_id=$(docker ps --format "{{.ID}}" | sed -n "${container_number}p") | |
if [ -z "$container_id" ]; then | |
echo "Invalid selection or container ID not found." | |
exit 1 | |
fi | |
# Start bash session in the selected container | |
echo "Starting bash session in container $container_id..." | |
docker exec -it $container_id /bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment