-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_exec.sh
executable file
·55 lines (48 loc) · 1.12 KB
/
docker_exec.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
if [ -f ".env" ]; then
source .env
fi
flag_i=false
flag_t=false
command=""
echo_help() {
echo "Uso: $0 [-i] [-t] comando exec"
echo "Descripción: Script para ejecutar 'docker exec' en el contenedor"
echo "Opciones:"
echo " -i Interactivo."
echo " -t Asignación de terminal."
}
while getopts ":ith" flag; do
case $flag in
i)
flag_i=true
;;
t)
flag_t=true
;;
h)
echo_help
exit 0
;;
\?)
echo "Opción inválida: -$OPTARG. Usa -h para ver la ayuda." >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ $# -gt 0 ]; then
command="$@"
else
echo "Se requiere un comando después de las opciones."
exit 1
fi
if [ "$flag_i" = true ] && [ "$flag_t" = true ]; then
docker exec -it $APACHE_CONTAINER $command
elif [ "$flag_t" = true ]; then
docker exec -t $APACHE_CONTAINER $command
elif [ "$flag_i" = true ]; then
docker exec -i $APACHE_CONTAINER $command
else
docker exec $APACHE_CONTAINER $command
fi