blob: 6728e1cc34a76dc73ff0582bf639e3c6f670d936 (
plain) (
blame)
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
|
#!/bin/bash
# Exec shell into running container.
set -euo pipefail
select_container() {
docker ps | fzf \
--header-lines=1 \
--select-1 --exit-0 \
--preview-label="Logs" \
--preview-window=down,10 \
--preview "docker logs --tail=9 {1}" | awk '{print $1}'
}
main() {
if [ $# -eq 0 ]; then
container=$(select_container)
else
if ! docker inspect "$1" >/dev/null 2>&1; then
echo "No running container: $1"
exit 1
fi
container="$1"
fi
for command in /bin/bash /bin/sh; do
docker exec --interactive --tty "$container" "$command" || continue && exit 0
done
}
main "$@"
|