Transmission Behind OpenVPN Client

I have 2 hosts; one in Germany and one in Turkey.

My main server is in Turkey, but I wanted to make some transmission's connections through Germany. Since transmission disabled proxy support, I had to set up an OpenVPN server in Germany. After that, on a Docker container in Turkey, transmission would connect to Germany.

The set up for Dockerfile is;

# base image
FROM ubuntu:16.04  
# install necessary stuff
RUN apt update  
RUN apt install -y openvpn  
RUN apt install -y transmission-daemon  
RUN mkdir -p /opt/Downloads /var/lib/transmission-daemon  
# copy local files to image
ADD /root/  
ADD client.ovpn /etc/openvpn/client.ovpn  
ADD settings.json /etc/transmission-daemon/settings.json  
# this will be shared directory
VOLUME ["/opt/Downloads", "/var/lib/transmission-daemon"]  
# not needed
WORKDIR /root  
# to access 9091 port, defined in settings.json
EXPOSE 9091  
# not needed
ENV HOME /root  
# pinging keeps vpn alive, and tailing keeps docker on.
CMD ["/root/"]  
# commands to build and execute.
# sudo docker build -t cagricelebi/trans-ovpn:v6 .
# sudo docker run --name trans-ovpn -p 9091:9091 -v /opt/Downloads:/opt/Downloads -v /var/lib/transmission-daemon:/var/lib/transmission-daemon --cap-add=NET_ADMIN --device=/dev/net/tun --dns --dns -d cagricelebi/trans-ovpn:v6

This is helper script in the image;

nohup openvpn --config /etc/openvpn/client.ovpn 2>&1 >/dev/null &  
sleep 10  
service transmission-daemon start  
nohup ping 2>&1 >/dev/null & # VPN Space:  
tail -f /dev/null  

Instead of tail in the final line, you can move "openvpn --config ..." connection string in the bottom, thus making any failure in VPN to stop the service. Another similar project, docker-transmission-openvpn, used this approach.

And this is trans-ovpn.service for systemd;

Description=cagricelebi/trans-ovpn docker container  

ExecStartPre=-/usr/bin/docker kill trans-ovpn  
ExecStartPre=-/usr/bin/docker rm trans-ovpn  
ExecStart=/usr/bin/docker run --name trans-ovpn -p 9091:9091 -v /opt/Downloads:/opt/Downloads -v /var/lib/transmission-daemon:/var/lib/transmission-daemon --cap-add=NET_ADMIN --device=/dev/net/tun --dns --dns -d cagricelebi/trans-ovpn:v6


You can add it to startup via systemctl.

sudo systemctl enable /etc/systemd/system/trans-ovpn.service  

PS: To do note for myself: Need to specify group and userId for the transmission service inside docker.


comments powered by Disqus