dotfiles/.dockerfunc

265 lines
6.5 KiB
Plaintext
Raw Normal View History

2015-10-24 00:57:07 +02:00
#!/bin/bash
# Bash wrappers for docker run commands
# inspired by https://github.com/jfrazelle/dotfiles/ <3
#
# Helper Functions
#
dcleanup() {
2015-12-15 16:51:37 +01:00
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
2015-10-24 00:57:07 +02:00
}
del_stopped() {
2015-12-15 16:51:37 +01:00
local name=$1
local state=$(docker inspect --format "{{.State.Running}}" $name 2>/dev/null)
2015-10-24 00:57:07 +02:00
2015-12-15 16:51:37 +01:00
if [[ "$state" == "false" ]]; then
docker rm $name
fi
2015-10-24 00:57:07 +02:00
}
relies_on() {
2015-12-15 16:51:37 +01:00
local containers=$@
2015-10-24 00:57:07 +02:00
2015-12-15 16:51:37 +01:00
for container in $containers; do
local state=$(docker inspect --format "{{.State.Running}}" $container 2>/dev/null)
2015-10-24 00:57:07 +02:00
2015-12-15 16:51:37 +01:00
if [[ "$state" == "false" ]] || [[ "$state" == "" ]]; then
echo "$container is not running, starting it for you."
$container
fi
done
2015-10-24 00:57:07 +02:00
}
2015-10-30 11:37:04 +01:00
# Applications...
2015-11-04 18:00:37 +01:00
bro() {
2015-10-30 11:37:04 +01:00
docker run -it --rm \
fschl/bropages \
2015-11-04 18:00:37 +01:00
bro "$@"
2015-10-30 11:37:04 +01:00
}
2015-10-24 00:57:07 +02:00
chrome() {
2015-12-15 16:51:37 +01:00
# add flags for proxy if passed
local proxy=
local map=
local args=$@
del_stopped chrome
# one day remove /etc/hosts bind mount when effing
# overlay support inotify, such bullshit
2015-12-26 12:05:14 +01:00
# --memory 2gb \
2015-12-15 16:51:37 +01:00
docker run -d \
--net host \
-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 \
--device /dev/snd \
--device /dev/dri \
--device /dev/video0 \
--group-add audio \
--group-add video \
2015-12-26 12:05:14 +01:00
--name="chrome" \
fschl/chrome:latest --user-data-dir=/data
#--force-device-scale-factor=1 \
#--proxy-server="$proxy" --host-resolver-rules="$map" "$args"
2015-10-24 00:57:07 +02:00
}
eclipse() {
2015-12-15 16:51:37 +01:00
del_stopped eclipse
2015-11-25 16:13:11 +01:00
2015-12-15 16:51:37 +01:00
docker run -d \
2015-10-24 00:57:07 +02:00
--net host \
2015-12-26 12:05:14 +01:00
--name="eclipse" \
2015-11-02 20:35:18 +01:00
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
2015-12-15 16:51:37 +01:00
-v $HOME/projects/java/workspace:/home/eclipse/workspace \
2015-10-24 00:57:07 +02:00
-v $HOME/.eclipse/plugins:/opt/eclipse/plugins \
-v $HOME/.eclipse/configuration:/opt/eclipse/configuration \
-v $HOME/.sonar:/home/eclipse/.sonar \
2015-12-15 16:51:37 +01:00
fschl/eclipse:latest
exit 0;
2015-10-24 00:57:07 +02:00
}
2016-03-08 10:37:50 +01:00
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 \
--name gimp \
fschl/gimp
}
2015-11-02 20:35:18 +01:00
go() {
2016-03-08 10:37:50 +01:00
docker run -i --rm \
2015-11-02 20:35:18 +01:00
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
2016-03-08 10:37:50 +01:00
fschl/golang-dev:latest go "$@"
2015-11-04 18:00:37 +01:00
}
2015-11-02 20:35:18 +01:00
2015-12-15 01:20:42 +01:00
icedove() {
del_stopped icedove
docker run -d \
2015-12-26 12:05:14 +01:00
--name="icedove" \
2015-12-15 01:20:42 +01:00
-v /etc/localtime:/etc/localtime:ro \
-v $HOME/Downloads/:/root/Downloads \
-v $HOME/.thunderbird/:/root/.icedove \
-v $HOME/.gnupg/:/root/.gnupg \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
2015-12-26 12:05:14 +01:00
fschl/icedove:latest
exit 0;
2015-12-15 01:20:42 +01:00
}
2015-10-30 11:37:04 +01:00
latex() {
del_stopped latex
docker run -it --rm \
--net host \
-v $(pwd):/usr/src/latex \
--workdir="/usr/src/latex" \
fschl/latex "$@"
}
2015-12-16 13:28:20 +01:00
libreoffice() {
2015-12-15 01:20:42 +01:00
del_stopped libreoffice
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
-v $HOME/Documents:/root/Documents \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--name libreoffice \
fschl/libreoffice
}
2015-12-16 13:28:20 +01:00
# start from a directory which contains a openvpn config file named 'config.ovpn'
# cert and key files should be in the same directory or relatively referencable
# from the config file
openvpn() {
del_stopped openvpn
docker run -it --rm \
2015-12-26 12:05:14 +01:00
--name="openvpn" \
2015-12-16 13:28:20 +01:00
--net host \
--device /dev/net/tun:/dev/net/tun \
--cap-add NET_ADMIN \
-v "$PWD":/etc/openvpn \
fschl/openvpn:latest config.ovpn
}
2015-10-24 00:57:07 +02:00
pulseaudio() {
2015-12-15 01:20:42 +01:00
del_stopped pulseaudio
2015-10-24 00:57:07 +02:00
2015-12-15 01:20:42 +01:00
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
--device /dev/snd \
-p 4713:4713 \
--restart always \
--name pulseaudio \
fschl/pulseaudio
2015-10-24 00:57:07 +02:00
}
2015-12-15 01:20:42 +01:00
# pulseaudio() {
# del_stopped pulseaudio
# docker run -d \
# -v /etc/localtime:/etc/localtime:ro \
# --device /dev/snd \
# -p 4713:4713 \
# --restart always \
# -v /var/run/dbus:/var/run/dbus \
# -v /etc/machine-id:/etc/machine-id \
# --name pulseaudio \
# fschl/pulseaudio
# }
2015-10-24 00:57:07 +02:00
skype() {
2015-12-15 01:20:42 +01:00
del_stopped skype
2015-10-24 00:57:07 +02:00
2015-12-15 01:20:42 +01:00
docker run -d \
-v $HOME/Downloads:/root/skype/Downloads \
2015-10-24 00:57:07 +02:00
-v /run/user/1000/pulse:/run/user/1000/pulse \
-v /var/lib/dbus:/var/lib/dbus \
-v ~/.pulse:/root/.pulse \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--device /dev/video0 \
--device /dev/snd \
--name skype \
--net host \
fschl/skype
}
2015-11-02 20:35:18 +01:00
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 \
fschl/tor-browser
# exit current shell
exit 0
2015-11-02 20:35:18 +01:00
}
2015-12-20 23:49:15 +01:00
2016-01-03 10:38:57 +01:00
transmission() {
del_stopped transmission
docker run -d \
-v /etc/localtime:/etc/localtime:ro \
-v $HOME/Downloads:/transmission/download \
-v $HOME/.transmission:/transmission/config \
-p 9091:9091 \
-p 51413:51413 \
-p 51413:51413/udp \
--name transmission \
fschl/transmission
}
2015-12-20 23:49:15 +01:00
vlc() {
del_stopped vlc
local args=$@
docker run -it \
-v "$args":/home/vlc \
-v /etc/localtime:/etc/localtime:ro \
-v /tmp/.X11-unix:/tmp/.X11-unix \
2015-12-26 12:05:14 +01:00
-v /run/user/1000/pulse:/run/user/vlc/pulse \
2015-12-20 23:49:15 +01:00
-v /var/lib/dbus:/var/lib/dbus \
-v ~/.pulse:/root/.pulse \
-e DISPLAY=unix$DISPLAY \
-e GDK_SCALE \
-e GDK_DPI_SCALE \
--device /dev/snd \
--name vlc \
fschl/vlc
}