Docker stack inc. ExpressVPN

docker-compose.yml

# Docker compose to set up containers for all services you need:
# VPN
#   Sonarr, Radarr, Lidarr, Qbittorrent
# Non-VPN
#   Plex, get_iplayer
# Before running docker-compose, you should pre-create all of the following folders.
# Folders for Docker State:
#  /volume1/dockerdata.             - root where this docker-compose.yml should live
#  /volume1/dockerdata/plex         - Plex config and DB
#  /volume1/dockerdata/sonarr       - Sonarr config and DB
#  /volume1/dockerdata/radarr       - Radarr config and DB
#  /volume1/dockerdata/lidarr       - Lidarr config and DB
#  /volume1/dockerdata/qbt          - QBitorrent config and DB
#  /volume1/dockerdata/prowlarr     - Prowlarr config and DB
#  /volume1/dockerdata/get_iplayer  - Get_iPlayer config and DB
# Folders for Media etc:
#  /volume1/photo                   - Root storage for photo files
#  /volume1/music                   - Root storage for music files
#  /volume1/video                   - Root storage for video files
#  /volume1/video/TV                - folder for Sonarr/Plex TV shows
#  /volume1/video/Films             - folder for Radarr/Plex Movies
#  /volume1/video/Downloads         - QBT folder for TV downloads (that Sonarr will process)
#  /volume1/video/FilmDownloads     - QBT folder for Movie downloads (that Radarr will process)
#  /volume1/video/MusicDownloads    - QBT folder for Music downloads (that Lidarr will process)
#  /volume1/video/Downloads/iPlayer - Destination folder for get_iplayer. See https://github.com/Webreaper/SonarrAutoImport
# 
# Note that Sonarr and Radarr don't necessarily need the VPN if you're using Prowlarr for the indexers. 
# But Prowlarr should be behind the VPN to avoid ISPs that block indexers.

services:
    expressvpn:
        image: polkaned/expressvpn
        container_name: expressvpn
        environment:
            - ACTIVATION_CODE=YOUR_CODE_HERE
        cap_add:
            - NET_ADMIN
        devices:
            - "/dev/net/tun:/dev/net/tun"
        privileged: true
        tty: true
        ports:
            # QBT UI Port
            - 8090:8090
            # Bittorrent port
            - 6881:6881
            - 6881:6881/udp
            # Web port
            - 8080:8080
            - 9117:9117
            # Sonarr port
            - 8989:8989
            # Radarr port
            - 7878:7878
            # Lidarr port
            - 8686:8686
            # Prowlarr port
            - 9696:9696
        command: /bin/bash
        restart: unless-stopped

    qbittorrent:
        image: linuxserver/qbittorrent
        container_name: qbittorrent
        environment:
            - PUID=1024
            - PGID=101
            - TZ=Europe/London
            - UMASK_SET=022
            - WEBUI_PORT=8090
        volumes:
            - /volume1/dockerdata/qbt/config:/config
            - /volume1/video/Seeding:/downloads
            - /volume1/video/Downloads:/tvdownloads 
            - /volume1/video/FilmDownloads:/filmdownloads 
            - /volume1/video/MusicDownloads:/musicdownloads
        network_mode: service:expressvpn
        restart: unless-stopped

    prowlarr:
        image: linuxserver/prowlarr:develop
        container_name: prowlarr
        environment:
            - PUID=1024
            - PGID=101
            - TZ=GB
        volumes:
            - /volume1/dockerdata/prowlarr:/config
        restart: unless-stopped
        network_mode: service:expressvpn
        depends_on:
            - expressvpn
            - qbittorrent
            
    sonarr:
        image: linuxserver/sonarr:latest
        container_name: sonarr_v3
        environment:
            - PUID=1024
            - PGID=101
            - TZ=GB
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /volume1/dockerdata/sonarr/config:/config
            - /volume1/video/TV:/tv
            - /volume1/video/Downloads:/downloads
        restart: unless-stopped
        network_mode: service:expressvpn
        depends_on:
            - prowlarr
            - qbittorrent

    radarr:
        image: linuxserver/radarr:latest
        container_name: radarr_v3
        environment:
            - PUID=1024
            - PGID=101
            - TZ=GB
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /volume1/dockerdata/radarr3/config:/config
            - /volume1/video/Films:/movies
            - /volume1/video/FilmDownloads:/downloads
        restart: unless-stopped
        network_mode: service:expressvpn
        depends_on:
            - prowlarr
            - qbittorrent

    lidarr:
        image: linuxserver/lidarr
        container_name: lidarr
        environment:
            - PUID=1024
            - PGID=101
            - TZ=GB
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /volume1/dockerdata/lidarr/config:/config
            - /volume1/music:/music
            - /volume1/video/MusicDownloads:/downloads
        restart: unless-stopped
        network_mode: service:expressvpn
        depends_on:
            - prowlarr
            - qbittorrent
    plex:
        container_name: plex
        image: linuxserver/plex
        devices:
            - /dev/dri:/dev/dri
        privileged: true
        environment:
            PGID: '101'
            PUID: '1024'
            VERSION: docker
        network_mode: host
        restart: unless-stopped
        volumes:
            - /volume1/dockerdata/plex:/config:rw
            - /volume1/video/TV:/tv:rw
            - /volume1/video/Films:/movies:rw
            - /volume1/music:/music:rw
    get_player:
        container_name: get_iplayer
        image: kolonuk/get_iplayer
        environment:
            PGID: '101'
            PUID: '1024'
        ports:
            - 8181:8181/tcp
        restart: unless-stopped
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /volume1/dockerdata/get_iplayer:/root/.get_iplayer:rw
            - /volume1/video/Downloads/iPlayer:/root/output:rw  

ExpressVPN – Hourly random smart server reconnect (Linux)

This will force a disconnect, then a re-connect to a random server hourly. There are a few other options included. The original article can be sourced here.

Firstly open a terminal and type:

sudo crontab -e


This will open the CRON list where you can set script to run at certain intervals. In this case we want this event to happen on reboot.
Add at the bottom:

# MY CRON FILE
MAILTO=""
@reboot expressvpn connect


Now save the file by pressing [ctrl] + [X], then [Y], then [enter].
Now reboot your system.

sudo reboot


Once again in the terminal, type:

expressvpn status


This will tell you which server you are connected too. To make this switch locations automatically, type this in the terminal:

sudo nano /usr/sbin/smartexpressvpn.sh


Now paste this into the blank file:

expressvpn disconnect
expressvpn refresh

# Chose any of the below
# This will make you hop all over the world
VPN=$(expressvpn list all | tail -n +4 | awk '{ print $1 }' | shuf -n 1)

# This will make you hop around using recommended connections
# VPN=$(expressvpn list all | grep ‘\Y$’ | tail -n +4 | awk '{ print $1 }' | shuf -n 1)

# Use a custom list to connect to servers in the vicinity.
# VPN=$(cat /mnt/scripts/conf/expressvpn_EU_list.txt | tail -n +4 | awk '{ print $1 }' | shuf -n 1)

expressvpn connect $VPN


Save the file by pressing [ctrl] + [X], then [Y], then [enter].
Now we need to make this bash script file executable and we do that by running the following commands from terminal:

sudo chmod +x /usr/sbin/smartexpressvpn.sh


If you want to test the script, type this in the command line:

/usr/sbin/smartexpressvpn.sh


Check where you are connected by typing:

expressvpn status


This should have changed!
Now to make this run every hour of every day automagically!

sudo crontab -e


Modify the contents to:

# MY CRON FILE
MAILTO=""
@reboot expressvpn connect
0 */1 * * * /usr/sbin/smartexpressvpn.sh


Save the file by pressing [ctrl] + [X], then [Y], then [enter].

You’re done!
Every hour on the hour your expressvpn should change locations.
Thanks to Ubuntu 101 for the guide and the commenters for cleaning up the code.

😀