-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.dockerfunc
390 lines (354 loc) · 8.99 KB
/
.dockerfunc
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/bin/bash
######################################
# .dockerfunc
# ------------
# Bash wrappers for docker run commands
#
# Based on the amazing work of Jess Frazelle
#
# :author: Levi Olson
# :date: 1 Feb 2018
# :version: 0.0.1
######################################
export DOCKER_REPO_PREFIX=jess
dcleanup() {
local containers
mapfile -t containers < <(docker ps -aq 2>/dev/null)
docker rm "${containers[@]}" 2>/dev/null
local volumes
mapfile -t volumes < <(docker ps --filter status=exited -q 2>/dev/null)
docker rm -v "${volumes[@]}" 2>/dev/null
local images
mapfile -t images < <(docker images --filter dangling=true -q 2>/dev/null)
docker rmi "${images[@]}" 2>/dev/null
}
del_stopped() {
local name=$1
local state
state=$(docker inspect --format "{{.State.Running}}" "$name" 2>/dev/null)
if [[ "$state" == "false" ]]; then
docker rm "$name"
fi
}
relies_on() {
for container in "$@"; do
local state
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
}
######################
# Container Aliases
# ---------------------
######################
aws() {
docker run -it --rm \
-v "${HOME}/.aws:/root/.aws" \
--log-driver none \
--name aws \
${DOCKER_REPO_PREFIX}/awscli "$@"
}
cadvisor() {
docker run -d \
--restart always \
-v /:/rootfs:ro \
-v /var/run:/var/run:rw \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
-p 1234:8080 \
--name cadvisor \
google/cadvisor
hostess add cadvisor "$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' cadvisor)"
browser-exec "http://cadvisor:8080"
}
chrome() {
# add flags for proxy if passed
local proxy=
local map
local args=$*
if [[ "$1" == "tor" ]]; then
relies_on torproxy
map="MAP * ~NOTFOUND , EXCLUDE torproxy"
proxy="socks5://torproxy:9050"
args="https://check.torproject.org/api/ip ${*:2}"
fi
del_stopped chrome
# one day remove /etc/hosts bind mount when effing
# overlay support inotify, such bullshit
docker run -d \
--memory 6gb \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
-v "${HOME}/Downloads:/root/Downloads" \
-v "${HOME}/Pictures:/root/Pictures" \
-v "${HOME}/Torrents:/root/Torrents" \
-v "${HOME}/.chrome:/data" \
-v /dev/shm:/dev/shm \
-v /etc/hosts:/etc/hosts \
--security-opt seccomp:$HOME/chrome.json \
--device /dev/snd \
--device /dev/dri \
--device /dev/video0 \
--device /dev/usb \
--device /dev/bus/usb \
--group-add audio \
--group-add video \
--name chrome \
${DOCKER_REPO_PREFIX}/chrome --user-data-dir=/data \
--proxy-server="$proxy" \
--host-resolver-rules="$map" "$args"
}
chromium() {
# add flags for proxy if passed
local proxy=
local map
local args=$*
if [[ "$1" == "tor" ]]; then
relies_on torproxy
map="MAP * ~NOTFOUND , EXCLUDE torproxy"
proxy="socks5://torproxy:9050"
args="https://check.torproject.org/api/ip ${*:2}"
fi
del_stopped chromium
# one day remove /etc/hosts bind mount when effing
# overlay support inotify, such bullshit
docker run -d \
--memory 6gb \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
-v "${HOME}/Downloads:/root/Downloads" \
-v "${HOME}/Pictures:/root/Pictures" \
-v "${HOME}/Torrents:/root/Torrents" \
-v "${HOME}/.chrome:/data" \
-v /dev/shm:/dev/shm \
-v /etc/hosts:/etc/hosts \
--security-opt seccomp:$HOME/chrome.json \
--device /dev/snd \
--device /dev/dri \
--device /dev/video0 \
--device /dev/usb \
--device /dev/bus/usb \
--group-add audio \
--group-add video \
--name chromium \
${DOCKER_REPO_PREFIX}/chromium --user-data-dir=/data \
--proxy-server="$proxy" \
--host-resolver-rules="$map" "$args"
}
firefox() {
del_stopped firefox
relies_on pulseaudio
docker run -d \
--memory 6gb \
--net host \
--cpuset-cpus 0 \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v "${HOME}/.cache/mozilla:/root/.cache/mozilla" \
-v "${HOME}/.mozilla:/root/.mozilla" \
-v "${HOME}/Downloads:/root/Downloads" \
-v "${HOME}/Pictures:/root/Pictures" \
-v "${HOME}/Torrents:/root/Torrents" \
-e "DISPLAY=unix${DISPLAY}" \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--device /dev/snd \
--device /dev/dri \
--name firefox \
${DOCKER_REPO_PREFIX}/firefox "$@"
}
gimp() {
del_stopped gimp
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
-v "${HOME}/Pictures:/root/Pictures" \
-v "${HOME}/.gtkrc:/root/.gtkrc" \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--name gimp \
${DOCKER_REPO_PREFIX}/gimp
}
hollywood() {
docker run --rm -it \
--name hollywood \
${DOCKER_REPO_PREFIX}/hollywood
}
htop() {
docker run --rm -it \
--pid host \
--net none \
--name htop \
${DOCKER_REPO_PREFIX}/htop
}
mpd() {
del_stopped mpd
# adding cap sys_admin so I can use nfs mount
# the container runs as a unpriviledged user mpd
docker run -d \
--device /dev/snd \
--cap-add SYS_ADMIN \
-e MPD_HOST=/var/lib/mpd/socket \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/exports:/etc/exports:ro \
-v "${HOME}/.mpd:/var/lib/mpd" \
-v "${HOME}/.mpd.conf:/etc/mpd.conf" \
--name mpd \
${DOCKER_REPO_PREFIX}/mpd
}
nes() {
del_stopped nes
local game=$1
docker run -d \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
--device /dev/dri \
--device /dev/snd \
--name nes \
${DOCKER_REPO_PREFIX}/nes "/games/${game}.rom"
}
pulseaudio() {
del_stopped pulseaudio
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
--device /dev/snd \
-p 4713:4713 \
--restart always \
--group-add audio \
--name pulseaudio \
${DOCKER_REPO_PREFIX}/pulseaudio
}
spotify() {
del_stopped spotify
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v "${HOME}/.spotify:/home/spotify/.spotify" \
-v "${HOME}/.cache/spotify:/home/spotify/.cache/spotify" \
-e "DISPLAY=unix${DISPLAY}" \
-e QT_DEVICE_PIXEL_RATIO \
--security-opt seccomp:unconfined \
--device /dev/snd \
--device /dev/dri \
--group-add audio \
--group-add video \
--name spotify \
${DOCKER_REPO_PREFIX}/spotify
}
steam() {
del_stopped steam
relies_on pulseaudio
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/machine-id:/etc/machine-id:ro \
-v /var/run/dbus:/var/run/dbus \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v "${HOME}/.steam:/home/steam" \
-e "DISPLAY=unix${DISPLAY}" \
--link pulseaudio:pulseaudio \
-e PULSE_SERVER=pulseaudio \
--device /dev/dri \
--name steam \
${DOCKER_REPO_PREFIX}/steam
}
telnet() {
docker run -it --rm \
--log-driver none \
${DOCKER_REPO_PREFIX}/telnet "$@"
}
termboy() {
del_stopped termboy
local game=$1
docker run --rm -it \
--device /dev/snd \
--name termboy \
${DOCKER_REPO_PREFIX}/nes "/games/${game}.rom"
}
tor() {
del_stopped tor
docker run -d \
--net host \
--name tor \
${DOCKER_REPO_PREFIX}/tor
# set up the redirect iptables rules
sudo setup-tor-iptables
# validate we are running through tor
browser-exec "https://check.torproject.org/"
# exit current shell
# exit 0
}
torbrowser() {
del_stopped torbrowser
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--device /dev/snd \
--name torbrowser \
${DOCKER_REPO_PREFIX}/tor-browser
# exit current shell
# exit 0
}
tormessenger() {
del_stopped tormessenger
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--device /dev/snd \
--name tormessenger \
${DOCKER_REPO_PREFIX}/tor-messenger
# exit current shell
# exit 0
}
torproxy() {
del_stopped torproxy
docker run -d \
--restart always \
-v /etc/localtime:/etc/localtime:ro \
-p 9050:9050 \
--name torproxy \
${DOCKER_REPO_PREFIX}/tor-proxy
hostess add torproxy "$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' torproxy)"
}
traceroute() {
docker run --rm -it \
--net host \
${DOCKER_REPO_PREFIX}/traceroute "$@"
}
transmission() {
del_stopped transmission
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v "${HOME}/Torrents:/transmission/download" \
-v "${HOME}/.transmission:/transmission/config" \
-p 9091:9091 \
-p 51413:51413 \
-p 51413:51413/udp \
--name transmission \
${DOCKER_REPO_PREFIX}/transmission
hostess add transmission "$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' transmission)"
browser-exec "http://transmission:9091"
}
wireshark() {
del_stopped wireshark
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix${DISPLAY}" \
--cap-add NET_RAW \
--cap-add NET_ADMIN \
--net host \
--name wireshark \
${DOCKER_REPO_PREFIX}/wireshark
}