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 start.sh /root/start.sh
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/start.sh"]
# 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 4.2.2.5 --dns 8.8.8.8 -d cagricelebi/trans-ovpn:v6
This is helper script start.sh
in the image;
#!/bin/sh
nohup openvpn --config /etc/openvpn/client.ovpn 2>&1 >/dev/null &
sleep 10
service transmission-daemon start
nohup ping 192.168.5.1 2>&1 >/dev/null & # VPN Space: 192.168.5.0/24
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;
[Unit]
Description=cagricelebi/trans-ovpn docker container
After=docker.service
Requires=docker.service
[Service]
User=root
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 4.2.2.5 --dns 8.8.8.8 -d cagricelebi/trans-ovpn:v6
[Install]
WantedBy=multi-user.target
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.