|
|
- #!/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
- }
|