-
Notifications
You must be signed in to change notification settings - Fork 0
/
.docker-functions
133 lines (113 loc) · 2.93 KB
/
.docker-functions
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# Docker Functions
#
dcleanup(){
docker rm $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
}
del_stopped(){
local name=$1
local state=$(docker inspect --format "{{.State.Running}}" $name 2>/dev/null)
if [[ "$state" == "false" ]]; then
docker rm $name
fi
}
relies_on(){
local containers=$@
for container in $containers; do
local state=$(docker inspect --format "{{.State.Running}}" $container 2>/dev/null)
if [[ "$state" == "false" ]] || [[ "$state" == "" ]]; then
echo "$container is not running, starting it for you."
$container
fi
done
}
torch() {
docker rm `docker ps --no-trunc -aq`
}
chrome-headless() {
del_stopped chrome-headless
docker run -d \
-p 9222:9222 \
--security-opt seccomp=/etc/docker/seccomp/chrome.json \
--name chrome-headless \
justinribeiro/chrome-headless
}
rdp(){
del_stopped chrome
# one day remove /etc/hosts bind mount when effing
# overlay support inotify, such bullshit
docker run -d \
--net host \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--name rdp \
jess/rdesktop
}
ykman(){
del_stopped ykpersonalize
docker run --rm -it \
-v /etc/localtime:/etc/localtime:ro \
--device /dev/usb \
--device /dev/bus/usb \
--name ykman \
jess/ykman bash
}
ykpersonalize(){
del_stopped ykpersonalize
docker run --rm -it \
-v /etc/localtime:/etc/localtime:ro \
--device /dev/usb \
--device /dev/bus/usb \
--name ykpersonalize \
jess/ykpersonalize bash
}
yubico_piv_tool(){
del_stopped yubico-piv-tool
docker run --rm -it \
-v /etc/localtime:/etc/localtime:ro \
--device /dev/usb \
--device /dev/bus/usb \
--name yubico-piv-tool \
jess/yubico-piv-tool bash
}
alias yubico-piv-tool="yubico_piv_tool"
keypassxc(){
del_stopped keypassxc
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /usr/share/X11/xkb:/usr/share/X11/xkb:ro \
-e "DISPLAY=unix${DISPLAY}" \
-v /etc/machine-id:/etc/machine-id:ro \
-v $HOME/.config/keepassxc:/root/.config/keepassxc \
-v $HOME/Documents:/root/Documents \
--name keypassxc \
jess/keepassxc
}
alias keepassxc="keypassxc"
###
### Awesome sauce by @jpetazzo
###
command_not_found_handle () {
# Check if there is a container image with that name
if ! docker inspect --format '{{ .Author }}' "$1" >&/dev/null ; then
echo "$0: $1: command not found"
return
fi
# Check that it's really the name of the image, not a prefix
if docker inspect --format '{{ .Id }}' "$1" | grep -q "^$1" ; then
echo "$0: $1: command not found"
return
fi
docker run -ti -u $(whoami) -w "$HOME" \
$(env | cut -d= -f1 | awk '{print "-e", $1}') \
--device /dev/snd \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v /etc/localtime:/etc/localtime:ro \
-v /home:/home \
-v /tmp/.X11-unix:/tmp/.X11-unix \
"jess/$@"
}