Docker of Transmission-daemon

Fox
I want to deploy BT service use Docker in NAS. Because it is convenient to deploy in other places and more secure than native.

Backgroud

Here we use the Dockerfile to directly generate the Docker image locally.

In the open source world, such a theory that the less installed software is, the more secure it is. Although it is not entirely correct, it is still true in most environments.
Based on the above theory, we will not choose a larger Debian / Ubuntu Docker image (80 + MB), and instead use a small alpine image (4MB).

The files for this article have been posted on Github-haven200.

Using hub-docker mirrors

Chinese users, in order to improve the pull speed of Docker base image, here we use Azure image service.

1
2
3
4
5
:~$ cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://dockerhub.azk8s.cn"]
}
EOF && systemctl restart docker

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
FROM alpine:latest

MAINTAINER haven200 <haven200@gmail.com>

WORKDIR /opt/src

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apk/repositories \
&& apk update && apk add --no-cache transmission-daemon \
&& mkdir -p /etc/transmission-daemon && mkdir -p /mnt/bt/kodi

COPY run.sh /opt/src/run.sh

EXPOSE 12345/tcp 12345/udp 80/tcp

VOLUME [ "/mnt/bt/kodi" ]

CMD [ "/bin/sh","/opt/src/run.sh" ]
HEALTHCHECK CMD netstat -ln | grep 12345 || exit 1
  • FROM:creates a layer from the alpine:latest Docker image.。
  • MAINTAINER:Maintainer of the image.
  • WORKDIR:The current directory of the system in the docker image. You should always use absolute paths for your WORKDIR. Also, you should use WORKDIR instead of proliferating instructions like RUN cd … && do-something, which are hard to read, troubleshoot, and maintain.
  • RUN:builds your application with make.
  • COPY:adds files from your Docker client’s current directory.
  • EXPOSE:The EXPOSE instruction indicates the ports on which a container listens for connections.
  • VOLUME:This instruction should be used to expose any database storage area, configuration storage, or files/folders created by your docker container.
  • CMD: specifies what command to run within the container.
  • HEALTHCHECK:Tell the platform how to test that us application is healthy,

run.sh

Transmission configuration options are all in this file, and you can modify it yourself before compiling.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash

set -e

CONFIG_DIR=/etc/transmission-daemon
SETTINGS=$CONFIG_DIR/settings.json
TRANSMISSION=/usr/bin/transmission-daemon

GATEWAY_IP="$(ip route | grep default | awk '{print $3}')"

if [ -z $USERNAME ]; then
USERNAME="Transmission"
fi
if [ -z $PASSWORD ]; then
PASSWORD="password"
fi
if [ -z $RPC_PORT ]; then
RPC_PORT=80
fi

cat > $SETTINGS <<EOF
{
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
"download-dir": "/mnt/bt/kodi",
"download-limit": 100,
"download-limit-enabled": 0,
"incomplete-dir": "/mnt/bt/kodi/.unfinished",
"incomplete-dir-enabled": true,
"preallocation": 2,
"prefetch-enabled": true,
"start-added-torrents": false,
"umask": 91,
"watch-dir": "/mnt/bt/kodi/torrents/",
"watch-dir-enabled": true,
"trash-original-torrent-files": false,
"cache-size-mb": 128,
"dht-enabled": true,
"lpd-enabled": false,
"message-level": 2,
"encryption": 1,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"utp-enabled": true,
"idle-seeding-limit": 30,
"idle-seeding-limit-enabled": true,
"max-peers-global": 200,
"message-level": 1,
"peer-congestion-algorithm": "",
"peer-id-ttl-hours": 6,
"peer-limit-global": 200,
"peer-limit-per-torrent": 60,
"peer-port": 12345,
"peer-port-random-on-start": false,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
"peer-socket-tos": "default",
"pex-enabled": true,
"download-queue-enabled": true,
"download-queue-size": 3,
"queue-stalled-enabled": true,
"queue-stalled-minutes": 30,
"port-forwarding-enabled": true,
"ratio-limit": 1,
"ratio-limit-enabled": true,
"rename-partial-files": true,
"rpc-authentication-required": true,
"rpc-enabled": true,
"rpc-port": $RPC_PORT,
"rpc-bind-address": "0.0.0.0",
"rpc-host-whitelist": "",
"rpc-host-whitelist-enabled": true,
"rpc-url": "/transmission/",
"rpc-username": "$USERNAME",
"rpc-password": "$PASSWORD",
"rpc-whitelist": "127.0.0.1,$GATEWAY_IP",
"rpc-whitelist-enabled": true,
"scrape-paused-torrents-enabled": true,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"seed-queue-enabled": false,
"seed-queue-size": 10,
"speed-limit-down": 2048,
"speed-limit-down-enabled": true,
"speed-limit-up": 500,
"speed-limit-up-enabled": true,
"upload-limit": 100,
"upload-limit-enabled": 0,
"upload-slots-per-torrent": 14,
"alt-speed-down": 10240,
"alt-speed-enabled": false,
"alt-speed-time-begin": 0,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": true,
"alt-speed-time-end": 360,
"alt-speed-up": 2048,
"blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist"
}
EOF

exec $TRANSMISSION -f --config-dir $CONFIG_DIR

Build the Docker image

Run the following command in the Dockerfile directory

1
docker build -t haven200/transmission-daemon .

Run Image

1
2
3
4
5
6
docker run -d --name transmission-daemon \
-p 12345:12345/tcp \
-p 12345:12345/udp \
-p 80:80 \
-v /mnt/bt:/mnt/bt/kodi \
haven200/transmission-daemon

Set username and password

1
2
3
4
5
6
7
8
docker run -d --name transmission-daemon \
-p 12345:12345/tcp \
-p 12345:12345/udp \
-p 80:8080 \
-v /mnt/bt:/mnt/bt/kodi \
--env USERNAME=myname \
--env PASSWORD=mypassword \
haven200/transmission-daemon
  • USERNAME : Login Username
  • PASSWORD : Login Password

References: