Last active
May 30, 2020 06:14
-
-
Save shotgunner/e794b227b0ee225176250c4ee7e92800 to your computer and use it in GitHub Desktop.
simplified `docker exec -it <some_container> bash` to a alias function in bash
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
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
function goto() { | |
program="bash" | |
if [ -n "$2" ] | |
then | |
program="$2" | |
fi | |
if [ $(docker ps -q --filter "name=$1" | wc -l) -gt 1 ] | |
then | |
echo "too many containers exists with this name !" | |
elif [ $(docker ps -q --filter "name=$1" | wc -l) -lt 1 ] | |
then | |
echo "no container found !" | |
else | |
echo "We are going to this container => ${GREEN}" $(docker ps -q --filter "name=$1" --format '{{.Names}}') "${NC}" | |
docker exec -it $(docker ps -q --filter "name=$1") $program | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1- Add this function to end of your
.bashrc
file (or.zshrc
or others)2- run
source ~/.bashrc
3- use
goto <part_of_the_name_of_container>
NOTE: this command use
bash
as default command but you can usesh
or something else as second parameter like this:goto <part_of_the_name_of_container> sh