bit torrent in a docker container with VPN

I cut the cord on cable years ago and have been relying on SABnzbd + Sickbeard/Sonarr to grab all of my TV shows off usenet.  Occasionally, Sickbeard/Sonarr will miss an episode and by the time I go back to start looking for it, it is long gone on Usenet. This leaves me either dependent on watching the show “on demand” which means commercials or once in a while I will have to reach out to the pirate bay and bit torrent a copy which I usually try to avoid doing.

On the rare occasion I’ve had to do this in the past, the one time I forgot to check if my VPN was up and running, I get a nasty gram in the mail from ATT a few weeks later because apparently HBO was monitoring the torrent downloaders 😉

Enter docker – https://github.com/haugene/docker-transmission-openvpn/

Turns out this was so easy I don’t know why I did not look at doing it before.

My docker-compose.yml file  – direct from the github except for the last line:

version: ‘3.3’
services:
transmission-openvpn:
cap_add:
– NET_ADMIN
volumes:
– ‘/Downloads2/:/data’
environment:
– OPENVPN_PROVIDER=PIA
– OPENVPN_CONFIG=ca_montreal,ca_ontario,ca_toronto,ca_vancouver
– OPENVPN_USERNAME=XXXXX
– OPENVPN_PASSWORD=XXXXX
– LOCAL_NETWORK=192.168.0.0/16
– PUID=1000
logging:
driver: json-file
options:
max-size: 10m
ports:
– ‘9091:9091’
image: haugene/transmission-openvpn
restart: unless-stopped

I added the last line to make sure this always auto started when the host machine rebooted.

Coupled with a bash script to check the VPN this works perfectly

runs via cron every 10 minutes and makes sure the docker container’s IP is not the same as the host machines ip (e.g. VPN is up and running)

#!/bin/bash

function check {
     # hack to make sure docker container is using VPN
     ATT_IP=$(curl -s http://ipinfo.io/ip);

     # transmission container
     TID=$(docker ps |grep trans |awk ‘{print $1}’);
     TRANS_IP=$(docker exec -it $TID /bin/bash -c “curl -s http://ipinfo.io/ip”)
}

check
i=”0″
echo $ATT_IP
echo $TRANS_IP
while [ $i -lt 5 ]; do

     if [ “$ATT_IP” == “$TRANS_IP” ]; then
          echo “uh oh, docker running on ATT IP restarting and retrying in 60 seconds”
          docker restart $TID
          i=$[$i+1]
          sleep 60
          check
     else
          echo “we’re good, docker running on VPN IP $TRANS_IP”
          exit;
     fi
done

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *