Created
September 12, 2019 11:35
-
-
Save fabianofa/807dba5126bcbca6adfe52e33883bbe9 to your computer and use it in GitHub Desktop.
Shell script como alias para rodar comando em um container em específico
This file contains 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
#!/bin/bash | |
usage="$(basename "$0") [-h] [-w d e] -- script para executar um comando via docker exec -it | |
where: | |
-w diretório no container onde o comando será executado | |
-d nome do container, obtido via \$ docker ps | |
-e comando a ser executado. Caso o comando conter espaços deve estar envolto de aspas | |
exemplo de uso: | |
dkex -w /var/www/html/foo -d container_php71_1 -e 'composer install'" | |
while getopts ":w:d:e:h" opt; do | |
case $opt in | |
h) echo "$usage" | |
exit | |
;; | |
w) path="$OPTARG" | |
;; | |
d) container="$OPTARG" | |
;; | |
e) com="$OPTARG" | |
;; | |
esac | |
done | |
if [ -z "$path" ] | |
then | |
path=$1 | |
fi | |
if [ -z "$path" ] | |
then | |
path=$(pwd) | |
fi | |
docker exec -it -w $path $container $com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment