Deluge VPN
This project sees a Deluge container route its traffic through a Gluetun container’s network. A more thorough write-up is available here.
I set out on this project to create a Deluge container that would route through a virtual private network (VPN) and download files to my Network Attached Storage (NAS) server over the Network File System (NFS) or Samba (SMB) protocols, which I would then sort through manually depending on the file type. Or, I would let Deluge continue to seed the file nested behind a VPN.
This project requires the use of Gluetun, the details for which you can find in my Gluetun documentation.
Essentially, the way this works is that the Deluge Docker container is networked to the Gluetun container. This is done by having Gluetun handle Deluge’s port configuraiton (default is port 8112
), which works because Deluge is networked to it. So when you go to http://SERVERIP:8112
, you get the Deluge web UI with a different IP address than your public one.
The second step to this project was linking the Deluge container to a downloads folder on my NAS so that I wouldn’t use the local storage on my server, which I would then have to transfer to the NAS and sort manually. With this configuration, the host server itself is linked to a download folder on my NAS via NFS (which I find works better since my server runs Debian), which I added as a volume in the Deluge container. When a file downloads to this folder, I am able to access it on my NAS and sort it from there.
This saves a monumental amount of time and it is rather simple to set up. I highly recommend that all homelabbers have a NAS of some kind, and linking servers to it is a key factor in its overall convenience.
Prerequisites and preparation
Here is what you need to get started on this project.
Prerequisites
- A server, preferably with Debian, Ubuntu, or Alpine Linux installed that you are connected to locally or over SSH.
- Docker and Docker Compose installed. (To avoid adding
sudo
, be sure to add your user to the docker group.) - A text editor, such as nano or VSCode connected over SSH.
- A NAS with samba (SMB) file sharing enabled.
- An empty mount point for the SMB file share (e.g.
/mnt
or~/downloads
). - A knowledge of navigating a Linux filesystem.
Limitations
This project has one notable limitation. If you use the Watchtower container to keep your other containers up-to-date, you will need to recreate the Deluge container every time Gluetun gets an update. To avoid this issue, do not use Watchtower, but that would require manual Gluetun updating.
If the Deluge container goes down, simply navigate to its folder and recreate the container with the same Docker Compose command you will see later in these instructions.
Preparation
- Create a Docker folder.
mkdir docker
- Create a Deluge folder inside the Docker one you just created.
mkdir docker/deluge
- Create a config folder on Docker host. (File structure depends on installation and personal preferences.)
mkdir docker/deluge/config
- Create a downloads folder if one does not already exist. (Important for mounting the SMB share properly!)
mkdir downloads
- Create a SMB credentials file.
nano ~/.smbcredentials
- Insert the following into the blank file, making sure to use your own SMB credentials.
username=USERNAME
password=PASSWORD
- Exit the text editor and set proper permissions for the credentials file.
chmod 600 ~/.smbcredentials
- Add the SMB share to the
/etc/fstab
file, appending a new line.//SERVERIP/SHARENAME /MOUNTPOINT cifs credentials=/home/$USER/.smbcredentials 0 0
- Example:
//192.168.1.100 /home/johnsmith/downloads cifs credentials=/home/johnsmith/.smbcredentials 0 0
- If CIFS-utils is not installed, install it.
- If on Debian/Ubuntu:
sudo apt install cifs-utils
- If on Alpine:
sudo apk add cifs-utils
- If on Debian/Ubuntu:
- Mount the SMB share.
sudo mount -a
Installing Deluge
Here are the steps you’ll need to get the Deluge container installed. You will be adjusting this later, but this section is to help you get going.
- Create a YAML file named
docker-compose.yml
in your text editor or IDE of your choice and save it to the directory created in Step 1 in Preparation.- In this example, the file is saved under
~/docker/deluge
.
- In this example, the file is saved under
- Copy the following code into the blank file.
--- version: "2.1" services: deluge: image: lscr.io/linuxserver/deluge:latest container_name: deluge environment: - PUID=1000 - PGID=1000 - TZ=YOUR_TIMEZONE_HERE (TZ FORMAT) volumes: - /home/USERNAME/docker/deluge/config:/config - /home/USERNAME/downloads:/downloads ports: - 8112:8112 - 6881:6881 - 6881:6881/udp restart: unless-stopped
- Fill in YOUR_TIMEZONE_HERE with an appropriate tz database format timezone, which you can find here.
- Fill in USERNAME with your user account’s username.
- Save the file, naming it
docker-compose.yml
. - Navigate to the deluge container folder where you saved docker-compose.yml.
cd docker/deluge
- Input the following command to start up the container for automatic installation.
docker-compose up -d
- Wait for the download and installation to finish.
- Once complete, open a web browser and enter the server’s IP address followed by port
8112
.- In this example, that would be
http://localhost:8112
- In this example, that would be
- The Deluge web UI should open. It will ask for a username and password.
- Input
admin
for username anddeluge
for password.
- Input
- You will see your server’s public IP address in the bottom right corner. Confirm this by checking it via a site such as What’s My IP?. My IP address is blurred for security reasons.
- The Deluge container is installed and ready for use if you don’t want it masked behind a VPN. Assuming that you do, open your terminal to the Deluge directory and type the following.
docker-compose down
- This will stop the Deluge container so that you can start Gluetun on port
8112
.
- Head over to the Gluetun instructions to learn how to set up the VPN tunnel and start it before proceeding to the next Deluge section.
Configuring the Deluge VPN
Here are the steps that you’ll need to set up Deluge to connect through the Gluetun VPN tunnel.
- Navigate to where you saved the Deluge
docker-compose.yml
file.- In this example, it’s under
docker/deluge
.
- In this example, it’s under
- Your code should look like the following with TZ filled in with your time zone and USERNAME with your account username.
--- version: "2.1" services: deluge: image: lscr.io/linuxserver/deluge:latest container_name: deluge environment: - PUID=1000 - PGID=1000 - TZ=YOUR_TIMEZONE_HERE (TZ FORMAT) volumes: - /home/USERNAME/docker/deluge/config:/config - /home/USERNAME/downloads:/downloads ports: - 8112:8112 - 6881:6881 - 6881:6881/udp restart: unless-stopped
- However, since we have told Gluetun to be listening on port
8112
, you need to remove it from the Deluge container’s Docker Compose to avoid port conflicts. - You need to also link Deluge to Gluetun’s network. So your Docker Compose code should look like the following.
--- version: "2.1" services: deluge: image: lscr.io/linuxserver/deluge:latest container_name: deluge environment: - PUID=1000 - PGID=1000 - TZ=YOUR_TIMEZONE_HERE (TZ FORMAT) volumes: - /home/USERNAME/docker/deluge/config:/config - /home/USERNAME/downloads:/downloads ports: - 6881:6881 - 6881:6881/udp restart: unless-stopped network_mode: container: gluetun
- Exit the Docker Compose file, then type the following command.
docker compose up -d
- If you go to the web UI at
http://localhost:8112
, you should notice that your IP address in the bottom right corner is different than your public one.
Errors with network_mode: container
- The container should start up with the previous configuration. If, however, you run into errors, you can shut Deluge down with the following command while inside the Deluge directory.
docker compose down
- Open your
docker-compose.yml
file and try changingnetwork_mode
toservice: gluetun
like the below code.
--- version: "2.1" services: deluge: image: lscr.io/linuxserver/deluge:latest container_name: deluge environment: - PUID=1000 - PGID=1000 - TZ=YOUR_TIMEZONE_HERE (TZ FORMAT) volumes: - /home/USERNAME/docker/deluge/config:/config - /home/USERNAME/downloads:/downloads ports: - 6881:6881 - 6881:6881/udp restart: unless-stopped network_mode: service: gluetun
- Load up the container again with the following command.
docker compose up -d