-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_docker
126 lines (102 loc) · 3.52 KB
/
.bash_docker
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
#!/bin/bash
# Common Aliases
alias dip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
alias dim="docker images"
alias dex="docker exec -i -t"
alias dpa="docker ps -a"
alias denv="env | grep DOCKER_"
alias dips="docker ps -q | xargs docker inspect --format '{{ .NetworkSettings.IPAddress }} {{ .Name }} {{ .Config.Image }} {{ .State.Running }} {{ .Id }}'"
alias dstop='docker stop $(docker ps -a -q)'
# Docker Machine
function dmenv() {
eval "$(docker-machine env "${1:-default}")"
}
alias dmls="docker-machine ls"
alias dmstart="docker-machine start $1"
alias dmstop="docker-machine stop $1"
# Helper Functions
dcleanup(){
docker rm -v $(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
}
# Common / useful Docker containers
speedtest() { # Speed test network connection
docker run --name speedtext --rm --net host tianon/speedtest
}
lynx() { # Text-based web browser
docker run --name lynx --rm -it jess/lynx
}
# see http://blog.bennycornelissen.nl/bwc-gui-apps-in-docker-on-osx/
if [ $(which docker-machine) ]; then
export DOCKER_MACHINE=$(docker-machine active)
dminit() {
docker-machine start ${DOCKER_MACHINE}
dmshell
}
dmshell() {
eval $(docker-machine env ${DOCKER_MACHINE})
}
docker_if_not_running() {
if [ $(docker-machine status ${DOCKER_MACHINE}) != 'Running' ]; then
dminit
fi
}
dmhosts() {
DMHOSTNAME="dockerhost"
sudo -v
grep ${DMHOSTNAME} /etc/hosts > /dev/null && sudo sed -i '' "/${DMHOSTNAME}/d" /etc/hosts
sudo echo "$(docker-machine ip ${DOCKER_MACHINE}) ${DMHOSTNAME}" | sudo tee -a /etc/hosts
}
if [ $(docker-machine status ${DOCKER_MACHINE}) == 'Running' ]; then
dmshell &> /dev/null
fi
fi # end docker-machine
# xQuartz (required for running Dockers with GUI in OS X, together with socat)
xquartz_if_not_running() {
v_nolisten_tcp=$(defaults read org.macosforge.xquartz.X11 nolisten_tcp)
v_xquartz_app=$(defaults read org.macosforge.xquartz.X11 app_to_run)
if [ $v_nolisten_tcp == "1" ]; then
defaults write org.macosforge.xquartz.X11 nolisten_tcp 0
fi
if [ $v_xquartz_app != "/usr/bin/true" ]; then
defaults write org.macosforge.xquartz.X11 app_to_run /usr/bin/true
fi
netstat -an | grep 6000 &> /dev/null || open -a XQuartz
while ! netstat -an \| grep 6000 &> /dev/null; do
sleep 2
done
export DISPLAY=:0
}
close_xquartz() {
osascript -e 'quit app "xQuartz"'
}
firefox() {
xquartz_if_not_running
docker_if_not_running
xhost +$(docker-machine ip ${DOCKER_MACHINE})
docker run --name firefox --rm \
--memory 512mb --net host --security-opt seccomp:unconfined \
-e DISPLAY=$(docker-machine inspect ${DOCKER_MACHINE} --format={{.Driver.HostOnlyCIDR}} | cut -d'/' -f1):0 \
jess/firefox
close_xquartz
}
tor() {
xquartz_if_not_running
docker_if_not_running
xhost +$(docker-machine ip ${DOCKER_MACHINE})
docker run --name tor --rm \
--privileged \
-e DISPLAY=$(docker-machine inspect ${DOCKER_MACHINE} --format={{.Driver.HostOnlyCIDR}} | cut -d'/' -f1):0 \
jess/tor-browser
close_xquartz
}
chrome() {
xquartz_if_not_running
docker_if_not_running
xhost +$(docker-machine ip ${DOCKER_MACHINE})
docker run --name chrome --rm \
--memory 512mb --net host --security-opt seccomp:unconfined \
-e DISPLAY=$(docker-machine inspect ${DOCKER_MACHINE} --format={{.Driver.HostOnlyCIDR}} | cut -d'/' -f1):0 \
jess/chrome
close_xquartz
}