hernandito Posted May 8, 2015 Share Posted May 8, 2015 I got so sick of cutting and pasting commands like the below to enter into a specific container: docker exec -t -i 37fcc75e886d /bin/bash So I manually created a script that, with some editing on your part, you easily enter into the command line of your various dockers. I called my script "menu") and by typing one of the numbers, I can enter the container. In order to edit the script to use the containers you have, type: docker ps Make note of the names of the containers you want all the way on the left hand column. These are the names you have to edit on the script below to easily activate. #!/bin/bash # This script will test if you have given a leap year or not. clear set -e #Path to php binary export PHP_PATH="/usr/bin/php" #Path to your romance directory export NEWZNAB_DIR="/var/www/nZEDb/misc" echo " " echo " " echo -e '\E[37;44m'"\033[1m \033[0m" echo -e '\E[33;44m'"\033[1m Docker Activation Menu \033[0m" echo -e '\E[37;44m'"\033[1m \033[0m" echo " " echo -e "\033[1;33;40m Please type number of activity you would like to perform:\033[1;33;40m" echo " " echo -e " 1. \033[0;32;40m Calibre \033[1;33;40m" echo -e " 2. \033[0;32;40m Apache-PHP-phpMyAdmin \033[1;33;40m" echo -e " 3. \033[0;32;40m MariaDB \033[1;33;40m" echo -e " 4. \033[0;32;40m Dropbox \033[1;33;40m " echo -e " " echo " " echo -e "\033[5m Type number and [ENTER]: " tput sgr0 echo " " read mychoice tput sgr0 echo " " if [ "$mychoice" = 1 ] then clear echo " " echo -e '\E[30;42m'"\033[1m \033[0m" echo -e '\E[30;42m'"\033[1m Calibre Container \033[0m" echo -e '\E[37;42m'"\033[1m \033[0m" echo " " docker exec -it CalibreServer bash elif [ "$mychoice" = 2 ] then clear echo " " echo -e '\E[30;42m'"\033[1m \033[0m" echo -e '\E[30;42m'"\033[1m Apache-PHP Container \033[0m" echo -e '\E[37;42m'"\033[1m \033[0m" echo " " docker exec -it Apache-PHP-Adminer bash elif [ "$mychoice" = 3 ] then clear echo " " echo -e '\E[30;42m'"\033[1m \033[0m" echo -e '\E[30;42m'"\033[1m MariaDB Container \033[0m" echo -e '\E[37;42m'"\033[1m \033[0m" echo " " docker exec -it MariaDB bash elif [ "$mychoice" = 4 ] then clear echo " " echo -e '\E[30;42m'"\033[1m \033[0m" echo -e '\E[30;42m'"\033[1m Dropbox Container \033[0m" echo -e '\E[37;42m'"\033[1m \033[0m" echo " " docker exec -it Dropbox bash else echo -e "\033[1;35;40mYou must enter a number between 1 and 6. \033[1;33;41m Exiting! " tput sgr0 fi Put this script somewhere on your unRAID path to activate from any folder. I followed this thread on how to add folders to your paths. I have not tested as I am in the middle of a pre-clear and cannot reboot. http://lime-technology.com/forum/index.php?action=post;quote=70080;topic=7220.0;last_msg=70116 I wish there was a way to automatically do this, but this is as far as I can go with my skills. I hope this makes sense and that it is helpful. Quote Link to comment
sparklyballs Posted May 8, 2015 Share Posted May 8, 2015 #Path to your romance directory that made me giggle for some reason. Quote Link to comment
ijuarez Posted May 8, 2015 Share Posted May 8, 2015 It's really close for pron! Quote Link to comment
hernandito Posted May 9, 2015 Author Share Posted May 9, 2015 Funny.... to be honest... I was running an NZB indexer and I indexed ebooks... There were TONS of romance and erotic novels, and I created scripts to filter those out and erase them... you can see the scripts in my Github repo... I recycled my old script for the docker connection and I guess I left some old code in there. Quote Link to comment
ljm42 Posted May 9, 2015 Share Posted May 9, 2015 I wish there was a way to automatically do this Turns out it is really hard to parse the output of "docker ps" to get the names of all the containers I spent way too much time Googling tr/sed/rev/cut/sort and finally came up with a solution that worked: https://gist.github.com/ljm42/2b3bfd8ff886015bbce8 This will present you with a list of all the running containers and "docker exec" into the one you choose. Thanks for getting me started on this, it should make it a lot easier to move between containers. Quote Link to comment
bonienl Posted May 9, 2015 Share Posted May 9, 2015 I wish there was a way to automatically do this Turns out it is really hard to parse the output of "docker ps" to get the names of all the containers I spent way too much time Googling tr/sed/rev/cut/sort and finally came up with a solution that worked: https://gist.github.com/ljm42/2b3bfd8ff886015bbce8 This will present you with a list of all the running containers and "docker exec" into the one you choose. Thanks for getting me started on this, it should make it a lot easier to move between containers. Perhaps this can help you: docker ps | awk 'NR==1 {offset=index($0,"NAMES")};NR>1{print substr($0,offset)}' It finds the index position of the name in the first line, and prints all subsequent lines from that position ... works like a treat! Quote Link to comment
ljm42 Posted May 9, 2015 Share Posted May 9, 2015 Perhaps this can help you: docker ps | awk 'NR==1 {offset=index($0,"NAMES")};NR>1{print substr($0,offset)}' It finds the index position of the name in the first line, and prints all subsequent lines from that position ... works like a treat! Very interesting! I didn't think the columns lined up well enough for the NAMES data to always start in the same position, but it seems it does. That awk solution is nice, thanks! Quote Link to comment
bonienl Posted May 9, 2015 Share Posted May 9, 2015 Perhaps this can help you: docker ps | awk 'NR==1 {offset=index($0,"NAMES")};NR>1{print substr($0,offset)}' It finds the index position of the name in the first line, and prints all subsequent lines from that position ... works like a treat! Very interesting! I didn't think the columns lined up well enough for the NAMES data to always start in the same position, but it seems it does. That awk solution is nice, thanks! I don't know if NAMES is always in the same position, that's why I let awk find the position dynamically and use that to print the docker names. Quote Link to comment
roland Posted May 24, 2015 Share Posted May 24, 2015 This is a great tool. I tried to combine the script and the parser and ended up with this: I hope you don't mind me playing with this code. Did not test it with dockers that have blanks in the name. (Not sure that is possible) #!/bin/bash ############################################### # This script will let you chose which docker container to exec into # # Original idea and concept by hernandito # DockerList by bonienl # ################################################ clear set -e #Define Colours ti=`tput setab 4;tput setaf 3` #Title Yellow on Blue ye=`tput setaf 3` #Yellow on default gr=`tput setaf 2` #Green on default mn=`tput setaf 4;tput setab 7` #menu he=`tput setaf 0;tput setab 2` #Heading New Docker d=`tput sgr0` #reset to default # rpad function needed in Docker Header # rpad String Len Pad function rpad { word="$1" while [ ${#word} -lt $2 ]; do word="$word$3"; done; echo "$word"; } # find all running dockers DockerList=($(docker ps | awk 'NR==1 {offset=index($0,"NAMES")};NR>1{print substr($0,offset)}')) # Display Menu echo " " echo " " echo -e "${yb} ${d}" echo -e "${yb} Docker Selector ${d}" echo -e "${yb} ${d}" echo " " echo " " for i in `seq 1 ${#DockerList[@]}` do echo -e "${ye} "$i". ${gr}"${DockerList[$i-1]}"${d}" done echo " " echo -e "${ye} 0. ${gr}Exit - do nothing ${d}" echo " " echo -e "${me} Type number and [ENTER]{d} " echo " " read mychoice echo "${d} " if [ "$mychoice" = 0 ] then clear exit 0 elif [ "$mychoice" -gt ${#DockerList[@]} ] then echo -e "You must enter a number between 0 and "${#DockerList[@]}" Exiting! ${d}" exit 0 else ## Connect to Docker clear echo -e "${he} ${d}" echo -e "${he} `rpad ${DockerList[$mychoice-1]} 41 " "` ${d}" echo -e "${he} ${d}" echo " " docker exec -it ${DockerList[$mychoice-1]} bash fi exit 0 https://raw.githubusercontent.com/Data-Monkey/unRAID/master/tools/DockerSelector.sh Quote Link to comment
hernandito Posted May 24, 2015 Author Share Posted May 24, 2015 Awesome stuff... Thank you guys... I do find this very useful. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.