Skip to content

Instantly share code, notes, and snippets.

@itailulu
Last active December 15, 2021 20:32
Show Gist options
  • Save itailulu/088738595db85e6a5eb29e649c54957e to your computer and use it in GitHub Desktop.
Save itailulu/088738595db85e6a5eb29e649c54957e to your computer and use it in GitHub Desktop.
Interactively bash into a docker container, without having to type it's full name - just pick its number!
dbsh() {
docker ps --format '{{.Names}}' | nl -s ") "
echo "Pick container"
read CONTAINER
CONTAINER_NAME=$(docker ps --format '{{.Names}}' | sed -n "${CONTAINER}p")
docker exec -ti $CONTAINER_NAME /bin/bash
}
@itailulu
Copy link
Author

itailulu commented Dec 3, 2021

Put this in your .zshrc (or .bashrc) file, and enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment