-
Notifications
You must be signed in to change notification settings - Fork 14
/
dockerme.sh
executable file
·64 lines (59 loc) · 1.92 KB
/
dockerme.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
56
57
58
59
60
61
62
63
64
#!/bin/bash
#
# This allows me to launch a container with the current folder
# mapper under /workdir. By default it's quite secure, allowing
# access to pulse and X11, but nothing else (no network).
#
# Launch with -n to have network - and with -r to be root.
usage() {
echo -e "Usage: $0 [-h] [-r] [-n] [-p 9999]"
echo -e "Where:"
echo -e "\t-h\t\tshow this help"
echo -e "\t-p port\t\tExpose port"
echo -e "\t-r\t\truns container with root user"
echo -e "\t-n\t\truns container with network enabled"
exit 1
}
rm -f /tmp/.docker.xauth*
XAUTH=/tmp/.docker.xauth
XSOCK=/tmp/.X11-unix
DRI=/dev/dri/card0
touch ${XAUTH}
xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f ${XAUTH} nmerge -
ROOT="-u user"
NETWORK="--network=none"
PORT=""
while getopts "hnrp:" o ; do
case "${o}" in
h)
usage
;;
n)
NETWORK=""
;;
r)
ROOT="-u root"
;;
p)
PORT="-p ${OPTARG}"
;;
*)
usage
;;
esac
done
exec docker run --rm $ROOT $NETWORK -it \
--entrypoint /bin/bash \
-v "$PWD":/workdir \
-v "$XDG_RUNTIME_DIR"/pulse:"$XDG_RUNTIME_DIR"/pulse \
-e DISPLAY \
-e XAUTHORITY=${XAUTH} \
-e PULSE_SERVER=unix:"$XDG_RUNTIME_DIR"/pulse/native \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /dev/shm:/dev/shm \
-v $DRI:$DRI \
-v ${XSOCK}:${XSOCK} \
-v ${XAUTH}:${XAUTH} \
-w /workdir \
${PORT} \
fasting3