-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.docker_aliases
More file actions
341 lines (314 loc) · 10.2 KB
/
.docker_aliases
File metadata and controls
341 lines (314 loc) · 10.2 KB
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
#!/bin/bash
# Suppress single quote warning:
# shellcheck disable=SC2016
X11_OPTS=(
--device /dev/dri
-e DISPLAY
-v /tmp/.X11-unix:/tmp/.X11-unix:ro
)
X11_COOKIE_OPTS=(
"${X11_OPTS[@]}"
-e "XCOOKIE=$(xauth list | grep unix | cut -f2 -d'/' | tr -cd '\11\12\15\40-\176' | sed -e 's/ / /g')"
)
SOUND_OPTS=(
--device /dev/snd
--group-add "$(getent group audio | cut -d: -f3)"
-e "PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native"
-v "${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native:ro"
)
DBUS_OPTS=(
-v /run/dbus:/run/dbus:ro
-v "${XDG_RUNTIME_DIR}/bus:${XDG_RUNTIME_DIR}/bus:ro"
-e DBUS_SESSION_BUS_ADDRESS
)
XDG_OPEN_SERVER_OPTS=(
-v "${XDG_RUNTIME_DIR}/xdg-open-server:${XDG_RUNTIME_DIR}/xdg-open-server:ro"
-v /usr/lib/xdg-open-server/xdg-open:/usr/local/bin/xdg-open:ro
)
GTK_OPTS=(
-v /usr/share/themes/:/usr/share/themes/
-v "${HOME}/.gtkrc-2.0:/home/USER/.gtkrc-2.0"
)
function docker-cleanup {
# Remove stopped containers
docker ps -aq --no-trunc | xargs docker rm
# Remove dangling/untagged images
docker images -q --filter dangling=true | xargs docker rmi
}
function docker-ip {
docker inspect --format '{{ .NetworkSettings.IPAddress }}' "${1}"
}
function docker-connect {
dependencies "${1}"
docker exec -it "${1}" "/bin/bash"
}
function docker-image-stop {
containers="$(docker ps -a -q --filter ancestor="${1}")"
for c in $containers; do
docker stop "${c}"
done
}
function dependencies {
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
}
function spotify {
local OPTS=("$*")
if [ "${OPTS[*]}" = "" ]; then
OPTS=(--rm --detach)
fi
local name="spotify"
echo -e "Launching spotify container"
mkdir -p "${HOME}/.spotify/.config"
mkdir -p "${HOME}/.spotify/.cache"
set -x
docker run "${OPTS[@]}" --name $name \
-v /etc/localtime:/etc/localtime:ro \
"${XDG_OPEN_SERVER_OPTS[@]}" \
"${X11_COOKIE_OPTS[@]}" \
"${SOUND_OPTS[@]}" \
"${DBUS_OPTS[@]}" \
-e DOCKER_SPOTIFY_FORCE_DEVICE_SCALE_FACTOR \
-v "${HOME}/.spotify/.config:/home/spotify/.config" \
-v "${HOME}/.spotify/.cache:/home/spotify/.cache" \
--entrypoint "/bin/bash" \
lizards/spotify \
-c 'touch ~/.Xauthority && xauth add $XCOOKIE && spotify --force-device-scale-factor=$DOCKER_SPOTIFY_FORCE_DEVICE_SCALE_FACTOR'
set +x
}
function slack {
local OPTS=("$*")
if [ "${OPTS[*]}" = "" ]; then
OPTS=(--rm --detach)
fi
local name='slack'
local user='slack'
echo -e "Launching Slack container"
mkdir -p "${HOME}/.slack/"
set -x
docker run "${OPTS[@]}" --name $name \
-v /etc/localtime:/etc/localtime:ro \
--ipc="host" \
--shm-size="1024" \
`# The below fixes: libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted` \
--security-opt seccomp=unconfined \
"${XDG_OPEN_SERVER_OPTS[@]}" \
"${X11_COOKIE_OPTS[@]}" \
"${SOUND_OPTS[@]}" \
"${DBUS_OPTS[@]}" \
"${GTK_OPTS[@]//USER/$user}" \
-v "${HOME}/.slack:/home/${user}/.config/Slack" \
-v "${HOME}:/media:ro" \
-e DOCKER_SLACK_FORCE_DEVICE_SCALE_FACTOR \
--entrypoint "/bin/bash" \
lizards/slack \
-c 'touch ~/.Xauthority && xauth add $XCOOKIE && /usr/lib/slack/slack --force-device-scale-factor=$DOCKER_SLACK_FORCE_DEVICE_SCALE_FACTOR'
set +x
}
function redis {
# Usage:
# One container: $ redis
# A master and one slave: $ redis slave
# A master and three slaves: $ redis slave 3
# Stop all containers using this image: $ redis stop
set -x
local image="bitnami/redis:latest"
local OPTS=("$*")
if [ "${OPTS[*]}" = "" ] || [ "${1}" == "slave" ]; then
OPTS=(--rm --detach)
fi
local name='redis-3.2.11'
local slave_name="${name}-slave"
if [ "${1}" == "stop" ]; then
docker-image-stop $image
else
if [ "${1}" == "slave" ]; then
slave_count=${2:-1}
dependencies redis
for i in $(seq 1 "${slave_count}"); do
docker run "${OPTS[@]}" \
--name "${slave_name}-${i}" \
--link "${name}:master" \
-e "REDIS_REPLICATION_MODE=slave" \
-e "REDIS_MASTER_HOST=master" \
-e "REDIS_MASTER_PORT_NUMBER=6379" \
-e ALLOW_EMPTY_PASSWORD=yes \
$image
done
else
docker run "${OPTS[@]}" \
--name "${name}" \
-e "REDIS_REPLICATION_MODE=master" \
-e ALLOW_EMPTY_PASSWORD=yes \
$image
fi
fi
set +x
}
function redis-cluster {
local name='redis-cluster-3.2.10'
if [ "${1}" == "stop" ]; then
docker stop $name
else
echo -e "Launching Redis Sharded Cluster container"
docker run --rm --detach --name $name \
-p 7000:7000 \
-p 7001:7001 \
-p 7002:7002 \
-p 7003:7003 \
-p 7004:7004 \
-p 7005:7005 \
-e CLUSTER_ONLY=true \
grokzen/redis-cluster:3.2.10
fi
}
function mysql-server {
local name='mysql-server'
if [ "${1}" == "stop" ]; then
docker stop $name
else
echo -e "Launching MySQL container"
docker run --rm --detach --name $name \
-v "${HOME}/work/mysql-data:/var/lib/mysql" \
-v "${HOME}/work/mysql-dumps:/mysql-dumps" \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_ROOT_HOST=172.17.0.1 \
mysql/mysql-server:5.7.20
fi
}
function mysql-workbench {
dependencies mysql-server
mkdir -p "${HOME}/.mysql-workbench/workbench"
mkdir -p "${HOME}/.mysql-workbench/workspace"
local name='mysql-workbench'
local user='developer'
echo -e "Launching MySQL workbench"
docker run --rm --detach --name $name \
"${X11_COOKIE_OPTS[@]}" \
"${DBUS_OPTS[@]}" \
-v "${HOME}/.mysql-workbench/workbench:/home/${user}/.mysql/workbench" \
-v "${HOME}/.mysql-workbench/workspace:/home/${user}/workspace" \
--link mysql-server \
openkbs/mysql-workbench \
/bin/bash -c "touch /home/${user}/.Xauthority && xauth add \$XCOOKIE && mysql-workbench"
}
function memcached {
local name='memcached'
if [ "${1}" == "stop" ]; then
docker stop $name
else
echo -e "Launching Memcached"
docker run --rm --detach --name $name \
memcached:latest
fi
}
function grpcui {
local name="${3:-grpcui}"
local grpc_service_host="${1:-localhost:8888}"
local grpc_ui_port="${2:-8002}"
echo -e "grpcui: connecting to ${grpc_service_host}"
docker run --rm --detach --name "${name}" \
--network host \
-e GRPCUI_SERVER="${grpc_service_host}" \
-e GRPCUI_PORT="${grpc_ui_port}" \
wongnai/grpcui \
&& echo -e "grpcui: http://localhost:${grpc_ui_port}"
}
function vlc {
local OPTS=("$*")
if [ "${OPTS[*]}" = "" ]; then
OPTS=(--rm --detach)
fi
local name="vlc"
echo -e "Launching VLC container"
mkdir -p "${HOME}/.vlc/.config"
docker run "${OPTS[@]}" --name $name \
-v /etc/localtime:/etc/localtime:ro \
"${X11_COOKIE_OPTS[@]}" \
"${SOUND_OPTS[@]}" \
"${DBUS_OPTS[@]}" \
-v "${HOME}/.vlc/.config:/home/vlc/.config" \
-v "${HOME}:/media:ro" \
--entrypoint "/bin/bash" \
lizards/vlc \
-c 'touch ~/.Xauthority && xauth add $XCOOKIE && vlc'
}
function vlc-screenshare {
local OPTS=("$*")
if [ "${OPTS[*]}" = "" ]; then
OPTS=(--rm --detach)
fi
local name="vlc"
echo -e "Launching VLC container"
mkdir -p "${HOME}/.vlc/.config"
docker run "${OPTS[@]}" --name $name \
-v /etc/localtime:/etc/localtime:ro \
"${X11_COOKIE_OPTS[@]}" \
"${SOUND_OPTS[@]}" \
"${DBUS_OPTS[@]}" \
-v "${HOME}/.vlc/.config:/home/vlc/.config" \
-v "${HOME}:/media:ro" \
--entrypoint "/bin/bash" \
lizards/vlc \
-c 'touch ~/.Xauthority && xauth add $XCOOKIE && vlc vlc --no-video-deco --no-embedded-video --screen-fps=5 --screen-top=0 --screen-left=3840 --screen-width=3840 --screen-height=2160 screen://'
}
function filezilla {
local name='filezilla'
local user='filezilla'
local OPTS=("$*")
if [ "${OPTS[*]}" = "" ]; then
OPTS=(--rm --detach)
fi
echo -e "Launching Filezilla container"
mkdir -p "${HOME}/.filezilla"
docker run "${OPTS[@]}" --name $name \
-v /etc/localtime:/etc/localtime:ro \
--net=host \
"${DBUS_OPTS[@]}" \
"${X11_COOKIE_OPTS[@]}" \
"${XDG_OPEN_SERVER_OPTS[@]}" \
"${GTK_OPTS[@]//USER/$user}" \
-v "${HOME}/.filezilla:/home/${user}/.config/filezilla" \
-v "${HOME}:/host" \
lizards/filezilla
}
function rutorrent {
local name='rutorrent'
local OPTS=("$*")
if [ "${1}" = "stop" ]; then
docker stop $name
else
if [ "${OPTS[*]}" = "" ]; then
OPTS=(--rm --detach)
fi
echo -e "Launching ${name} container"
mkdir -p "${HOME}/.rutorrent/config"
mkdir -p "${HOME}/.rutorrent/downloads"
docker run "${OPTS[@]}" --name=$name \
-v "${HOME}/.rutorrent/config:/config" \
-v "${HOME}/.rutorrent/downloads:/downloads" \
-e PGID="$(id --group)" \
-e PUID="$(id --user)" \
-e TZ="$(timedatectl | grep "Time zone" | awk '{print $3}')" \
-p 8080:80 \
-p 5000:5000 \
-p 51413:51413 \
-p 6881:6881/udp \
linuxserver/rutorrent
fi
}
function shellcheck {
for file in "$@"; do
file=$(realpath $file)
docker run --rm \
-v "${file}:/${file}:ro" \
koalaman/shellcheck \
-x "${file}"
done
}