Skip to content

Instantly share code, notes, and snippets.

@pancudaniel7
Created February 22, 2024 21:49
Show Gist options
  • Save pancudaniel7/8e483dbd4b0af3b232fc981405380751 to your computer and use it in GitHub Desktop.
Save pancudaniel7/8e483dbd4b0af3b232fc981405380751 to your computer and use it in GitHub Desktop.
#!/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