Skip to content

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

  1. Create a Docker folder.
    1. mkdir docker
  2. Create a Deluge folder inside the Docker one you just created.
    1. mkdir docker/deluge
  3. Create a config folder on Docker host. (File structure depends on installation and personal preferences.)
    1. mkdir docker/deluge/config
  4. Create a downloads folder if one does not already exist. (Important for mounting the SMB share properly!)
    1. mkdir downloads
  5. Create a SMB credentials file.
    1. nano ~/.smbcredentials
  6. Insert the following into the blank file, making sure to use your own SMB credentials.
    1. username=USERNAME
    2. password=PASSWORD
  7. Exit the text editor and set proper permissions for the credentials file.
    1. chmod 600 ~/.smbcredentials
  8. Add the SMB share to the /etc/fstab file, appending a new line.
    1. //SERVERIP/SHARENAME /MOUNTPOINT cifs credentials=/home/$USER/.smbcredentials 0 0
    2. Example: //192.168.1.100 /home/johnsmith/downloads cifs credentials=/home/johnsmith/.smbcredentials 0 0
  9. If CIFS-utils is not installed, install it.
    1. If on Debian/Ubuntu: sudo apt install cifs-utils
    2. If on Alpine: sudo apk add cifs-utils
  10. Mount the SMB share.
    1. 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.

  1. 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.
    1. In this example, the file is saved under ~/docker/deluge.
  2. 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
  1. Fill in YOUR_TIMEZONE_HERE with an appropriate tz database format timezone, which you can find here.
  2. Fill in USERNAME with your user account’s username.
  3. Save the file, naming it docker-compose.yml.
  4. Navigate to the deluge container folder where you saved docker-compose.yml.
    1. cd docker/deluge
  5. Input the following command to start up the container for automatic installation.
    1. docker-compose up -d
  6. Wait for the download and installation to finish.
  7. Once complete, open a web browser and enter the server’s IP address followed by port 8112.
    1. In this example, that would be http://localhost:8112
  8. The Deluge web UI should open. It will ask for a username and password.
    1. Input admin for username and deluge for password.
  9. 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.
  1. 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.
    1. docker-compose down
    2. This will stop the Deluge container so that you can start Gluetun on port 8112.
  2. 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.

  1. Navigate to where you saved the Deluge docker-compose.yml file.
    1. In this example, it’s under docker/deluge.
  2. 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
  1. 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.
  2. 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
  1. Exit the Docker Compose file, then type the following command.
    1. docker compose up -d
  2. 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

  1. 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.
    1. docker compose down
  2. Open your docker-compose.yml file and try changing network_mode to service: 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
  1. Load up the container again with the following command.
    1. docker compose up -d