#!/bin/bash # Bash wrappers for docker run commands # inspired by https://github.com/jfrazelle/dotfiles/ <3 export DOCKER_REPO_PREFIX=fschl # # Helper Functions # dcleanup() { # TODO: add list of non-disposable containers (eclipse, intelliJ, ...?) 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 } del_stopped() { local name=$1 local state=$(docker inspect --format "{{.State.Running}}" $name 2>/dev/null) if [[ "$state" == "false" ]]; then docker rm $name fi } relies_on() { local containers=$@ for container in $containers; do local 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 } # Applications... android-studio() { ANDROID_DIR="/home/fschl/projects/android" # for dir in .studio-home .gradle .idea .android/avd; do # mkdir -p $ANDROID_DIR/.docker-dev/$dir # done # TODO: mount /home/developer/android-sdk-linux # docker start android-studio ## You don't want to remove the container between uses, because many things installed ## via the _Android Studio GUI_ are only stored in the container. # del_stopped android-studio docker run -it \ --net=host \ --name android-studio \ --privileged \ -e DISPLAY \ -e SHELL=/bin/bash \ -e GRADLE_USER_HOME='/workspace/.docker-dev/.gradle/home' \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /dev/bus/usb:/dev/bus/usb \ -v $ANDROID_DIR/projects:/home/developer/AndroidStudioProjects \ -v $ANDROID_DIR:/workspace \ -v $ANDROID_DIR/.docker-dev/.studio-home:/home/developer/.AndroidStudio1.2 \ -v $ANDROID_DIR/.docker-dev/.android:/home/developer/.android \ ${DOCKER_REPO_PREFIX}/android:3 \ /bin/studio #exit 0; } # ansible() { # local args=$@ # local cur_dir=$(pwd) # local targetmount=$(basename $cur_dir) # docker run -it \ # --name ansible_$targetmount \ # -v ${cur_dir}:/src/$targetmount \ # -w /src/$targetmount \ # -v $HOME/.ssh/:/tmp/.ssh:ro \ # -v /etc/hosts:/etc/hosts:ro \ # ${DOCKER_REPO_PREFIX}/ansible:alpine \ # bash -c "$args" # } ant() { local args=$@ local cur_dir=$(pwd) local targetmount=$(basename $cur_dir) docker run -it --rm \ -v $(pwd):/src/$targetmount \ -w /src/$targetmount \ ${DOCKER_REPO_PREFIX}/antpp \ bash -c "$args" } arduino() { docker run \ -it \ --network=host \ --privileged \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /dev/ttyUSB0:/dev/ttyUSB0 \ -v $HOME/topics:/topics \ -v $HOME/projects:/home/developer/projects \ fschl/darduino:1.8.10 \ arduino } audacity(){ del_stopped audacity docker run -d \ -v /etc/localtime:/etc/localtime:ro \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e "DISPLAY=unix${DISPLAY}" \ -v $HOME/Downloads:/root/Downloads \ -v $HOME/Documents:/root/Documents \ -v $HOME/Music:/root/Music \ --device /dev/snd \ --group-add audio \ --name audacity \ jess/audacity } bro() { docker run -it --rm \ ${DOCKER_REPO_PREFIX}/bropages \ bro "$@" } chrome() { # 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 # --memory 2gb \ 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 \ --name="chrome" \ ${DOCKER_REPO_PREFIX}/chrome:latest --user-data-dir=/data #--force-device-scale-factor=1 \ #--proxy-server="$proxy" --host-resolver-rules="$map" "$args" } clion() { #del_stopped intelli_ult docker run -it \ --net host \ --name="clion" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/.CLion2016.3/:/home/developer/.CLion2016.3/ \ -v $HOME/.clion_config/:/home/developer/clion-2016.3.3/ \ -v $HOME/projects/cpp/clProjects:/home/developer/CLionProjects/ \ -p 8080:8080 \ ${DOCKER_REPO_PREFIX}/clion:latest } cordova() { docker run -it \ --name="cordova-cli" \ --net host \ -v $HOME/projects/cordova/:/src/ \ -v /dev/bus/usb:/dev/bus/usb \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -p 127.0.0.1:8000:8000 \ fschl/cordova bash } eclipse() { del_stopped eclipse docker run -d \ --net host \ --name="eclipse" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/workspace:/home/eclipse/workspace \ -v $HOME/.eclipse/plugins:/opt/eclipse/plugins \ -v $HOME/.eclipse/configuration:/opt/eclipse/configuration \ -v $HOME/.eclipse/sonar:/home/eclipse/.sonar \ ${DOCKER_REPO_PREFIX}/eclipse:latest # exit 0; } eneon() { del_stopped eclipse_neon # -v $HOME/.eclipse_neon/plugins:/opt/eclipse/plugins \ # -v $HOME/.eclipse_neon/configuration:/opt/eclipse/configuration \ # -v $HOME/.eclipse_neon/sonar:/home/eclipse/.sonar \ docker run -it \ --net host \ --name="eclipse_neon" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/workspace:/home/eclipse/workspace \ -v $HOME/dockerfiles/eclipse/eclipse.ini:/opt/eclipse/eclipse.ini:ro \ -v $HOME/.eclipse_neon/eclipse:/home/elipse/.eclipse/ \ -v $HOME/.eclipse_neon/plugins:/opt/eclipse/plugins/ \ -v $HOME/.eclipse_neon/configuration:/opt/eclipse/configuration \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/bin/docker \ --device /dev/video0 \ --group-add audio \ --group-add video \ ${DOCKER_REPO_PREFIX}/eclipse:neon # exit 0; } oxygen() { # del_stopped papyrus MYUSERID=$(id --user) echo "starting papyrus with uid" echo $MYUSERID # -v $BASE/.eclipse:/home/eclipse/.eclipse/ \ # -v $BASE/.gradle:/home/eclipse/.gradle/ \ # -v $BASE/.egradle:/home/eclipse/.egradle/ \ # -v $BASE/plugins:/opt/eclipse/plugins/ \ # -v $BASE/configuration:/opt/eclipse/configuration \ local BASE="/media/driveBay/Backups/eclipse-configs/oxygen_configs" docker run -it \ --net host \ --name="oxygen" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/workspace:/home/eclipse/workspace \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/bin/docker \ --user $MYUSERID \ --device /dev/video0 \ --group-add audio \ --group-add video \ ${DOCKER_REPO_PREFIX}/eclipse:oxygen \ sh -c "/opt/eclipse/eclipse" # exit 0; } photon() { # del_stopped papyrus MYUSERID=$(id --user) echo "starting papyrus with uid" echo $MYUSERID # -v $BASE/.eclipse:/home/eclipse/.eclipse/ \ # -v $BASE/.gradle:/home/eclipse/.gradle/ \ # -v $BASE/.egradle:/home/eclipse/.egradle/ \ # -v $BASE/plugins:/opt/eclipse/plugins/ \ # -v $BASE/configuration:/opt/eclipse/configuration \ local BASE="/media/driveBay/Backups/eclipse-configs/oxygen_configs" docker run -it \ --net host \ --name="photon" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/workspace:/home/eclipse/workspace \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/bin/docker \ --user $MYUSERID \ --device /dev/video0 \ --group-add audio \ --group-add video \ ${DOCKER_REPO_PREFIX}/eclipse:photon \ sh -c "/opt/eclipse/eclipse" # exit 0; } icedove() { del_stopped icedove MYUSERID=$(id --user) echo "starting with" echo $MYUSERID docker run -d \ --name="icedove" \ -v /etc/localtime:/etc/localtime:ro \ -v $HOME/Downloads/:/root/Downloads \ -v $HOME/Documents/:/root/Documents \ -v $HOME/.thunderbird/:/root/.thunderbird \ -v $HOME/.gnupg/:/root/.gnupg \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ ${DOCKER_REPO_PREFIX}/thunderbird:latest # -v $HOME/.thunderbird/:/root/.icedove \ # ${DOCKER_REPO_PREFIX}/icedove:latest exit 0; } inkscape() { del_stopped inkscape # -v $HOME/.Xauthority:/home/inkscaper/.Xauthority \ docker run --rm \ --name="inkscape" \ -v $HOME/Pictures:/home/inkscaper/Pictures \ -v $HOME/Documents:/home/inkscaper/Documents \ -u inkscaper \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ --net=host \ ${DOCKER_REPO_PREFIX}/inkscape:latest exit 0; } intelli_ult() { #del_stopped intelli_ult docker run -it \ --net host \ --name="intelli_ult" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/IdeaProjects:/home/developer/IdeaProjects/ \ -v m2-local:/root/.m2 \ -v $HOME/.IntelliJIdea_ult/:/home/developer/.IntelliJIdea2016.2/ \ -p 8080:8080 \ ${DOCKER_REPO_PREFIX}/intellij-ult:latest } java() { local args=$@ local cur_dir=$(pwd) local PROJECT=$(basename $cur_dir) del_stopped java_$PROJECT docker run -it \ --name="java_$PROJECT" \ -v $(pwd):/src/$PROJECT \ -w /src/$PROJECT \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ --net=host \ openjdk:8 \ bash -c "$args" } memo() { del_stopped memo_standalone docker run -it \ --name memo_standalone \ --net host \ -v $HOME/Documents:/root/Documents \ -v $HOME/Downloads:/root/Downloads \ -v $HOME/.memo:/root/.memo \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ ${DOCKER_REPO_PREFIX}/memo:latest #exit 0; } netbeans() { docker run -it \ --name netbeans \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v $HOME/.netbeans-docker:/home/developer/.netbeans \ -v $HOME/projects/java/workspace:/home/developer/NetBeansProjects \ -v $HOME/projects/java/workspace:/workspace \ ${DOCKER_REPO_PREFIX}/netbeans:latest } papyrus() { # del_stopped papyrus MYUSERID=$(id --user) echo "starting papyrus with uid" echo $MYUSERID # -v $BASE/.eclipse:/home/eclipse/.eclipse/ \ # -v $BASE/.gradle:/home/eclipse/.gradle/ \ # -v $BASE/.egradle:/home/eclipse/.egradle/ \ # -v $BASE/plugins:/opt/eclipse/plugins/ \ # -v $BASE/configuration:/opt/eclipse/configuration \ local BASE="/media/driveBay/Backups/eclipse-configs/oxygen_configs" docker run -it \ --net host \ --name="papyrus" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/workspace:/home/eclipse/workspace \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/bin/docker \ --user $MYUSERID \ --device /dev/video0 \ --group-add audio \ --group-add video \ ${DOCKER_REPO_PREFIX}/papyrus:latest \ sh -c "/opt/eclipse/eclipse" # exit 0; } rstudio(){ del_stopped rstudio docker run -d \ -v /etc/localtime:/etc/localtime:ro \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v $HOME/fastly-logs:/root/fastly-logs \ -v /dev/shm:/dev/shm \ -p 8787 \ -e DISPLAY=unix$DISPLAY \ --device /dev/dri \ --name rstudio \ rocker/rstudio exit 0; } scenebuilder() { del_stopped scenebuilder docker run -it \ --net host \ --name="scenebuilder" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ -v $HOME/projects/java/workspace:/home/eclipse/workspace \ ${DOCKER_REPO_PREFIX}/scenebuilder:latest "$@" exit 0; } # call with net-name as param tinc() { local tinc_dir="${HOME}/.config/etc-tinc" local NET_NAME=$1 if [[ -z ${NET_NAME} ]]; then echo "Error: tinc needs to be called with a net-name!!" else local tinc_name=$(grep -Po '(?<=Name = )[\w]+' ${tinc_dir}/${NET_NAME}/tinc.conf) local container_name="tinc_${tinc_name}" echo " running ${container_name} in net ${NET_NAME}" docker run -d \ --restart always \ --name=${container_name} \ --net=host \ --device=/dev/net/tun \ --cap-add NET_ADMIN \ --volume ${tinc_dir}:/etc/tinc \ ${DOCKER_REPO_PREFIX}/tinc \ -n ${NET_NAME} start -D fi } torbrowser() { del_stopped torbrowser docker run \ -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 } transmission() { del_stopped transmission torrent_dir="/media/driveBay/transmission" transmission_host="127.0.0.1:9091" docker run -d \ -v /etc/localtime:/etc/localtime:ro \ -v ${torrent_dir}:/transmission/download \ -v $HOME/.config/transmission_config:/transmission/config \ -p ${transmission_host}:9091 \ -p 51413:51413 \ -p 51413:51413/udp \ --name transmission \ ${DOCKER_REPO_PREFIX}/transmission echo "started transmission at http://${transmission_host}/transmission/web/" } wireshark() { del_stopped wireshark docker run -it \ -v /etc/localtime:/etc/localtime:ro \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v $(pwd):/home/wireshark \ -e DISPLAY=unix$DISPLAY \ --name wireshark \ jess/wireshark } woeusb() { del_stopped woeusb docker run -it \ -v /etc/localtime:/etc/localtime:ro \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v $(pwd):/home/woe \ -v /dev/:/shared_devs \ -v /mnt/:/mnted_devs \ -e DISPLAY=unix$DISPLAY \ --privileged \ --name woeusb \ ${DOCKER_REPO_PREFIX}/woeusb }