Skip to main content

gg

#!/bin/bash
# 구동중인 컨테이너로 쉽게 접속하기 위한 스크립트

clear
echo ""
echo " ###############################"
echo " # 현재 구동 중인 컨테이너     #"
echo " ###############################"
echo ""


LINE=0

CTNR_NM=`docker ps | grep -v CONTAINER | grep -v CREATED | grep -v STATUS | awk {'print $NF'}`
for i in $CTNR_NM
do
LINE=`expr $LINE + 1`
echo -n " "$LINE") "
echo $i
done

echo "";echo ""
echo -n " 접속할 컨테이너: "
read A

if [[ $A -le $LINE ]]
then
B=`expr $A + 0 2> /dev/null`

if [[ $A == $B ]]
then
CTNR=`docker ps | grep -v CONTAINER | grep -v CREATED | grep -v STATUS | awk {'print $NF'} | head -$A 2> /dev/null | tail -1`

echo "" ;echo "" ;echo ""
docker exec -ti $CTNR /bin/bash -l
fi

fi

fi