Guide

Run a 24/7 aria2 download server with Docker

An always-on aria2 in a container that survives restarts, runs a script when a download finishes, reports its health, and can be reached safely from anywhere. Four short files, and we ran every one of them.

Last updated: Tested with aria2 1.37.0

What you need

  • Docker with Compose v2 (docker compose version prints a version)
  • A machine that stays on: a server, mini-PC, Raspberry Pi or NAS
  • Optional: a router where you can forward one port for BitTorrent
  • Optional: a domain name, for HTTPS access from outside your home

What you will build

One container running aria2c. Everything worth keeping lives in two folders on the host, so you can rebuild or update the container without losing anything.

On the host ./config./downloads
In the container · aria2c
/configaria2.conf, the session file, the log, the DHT cache and your hook script
/downloadsFinished and partial downloads
6800/tcpJSON-RPC: WebUIs and apps control aria2 here
6888/tcp + udpBitTorrent peers and DHT

The four files

Create /opt/aria2 (or any folder) and put these files in it. They are exactly the files we tested.

  1. 01

    Dockerfile

    /opt/aria2/Dockerfile

    A small Alpine image with aria2 1.37.0. It creates the session file before aria2 starts, because aria2 refuses to start without it.

    Dockerfile
    FROM alpine:3.20
    RUN apk add --no-cache aria2 ca-certificates tzdata
    VOLUME ["/config", "/downloads"]
    EXPOSE 6800 6888 6888/udp
    # aria2 will not start if the session file is missing, so create it first
    ENTRYPOINT ["sh", "-c", "touch /config/aria2.session && exec aria2c --conf-path=/config/aria2.conf"]
  2. 02

    docker-compose.yml

    /opt/aria2/docker-compose.yml

    Mounts the two folders, publishes the ports and checks every minute that aria2 answers. The healthcheck uses system.listMethods, which needs no secret.

    docker-compose.yml
    services:
      aria2:
        build: .
        container_name: aria2
        restart: unless-stopped
        volumes:
          - ./config:/config
          - ./downloads:/downloads
        ports:
          - "6800:6800"
          - "6888:6888"
          - "6888:6888/udp"
        healthcheck:
          test: ["CMD-SHELL", "wget -qO- --post-data='{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"system.listMethods\"}' http://127.0.0.1:6800/jsonrpc | grep -q aria2.addUri"]
          interval: 60s
          timeout: 10s
          retries: 3
  3. 03

    aria2.conf

    /opt/aria2/config/aria2.conf

    Mounted, not built into the image: edit it and restart, with no rebuild. Change rpc-secret before the first start.

    aria2.conf
    dir=/downloads
    continue=true
    file-allocation=falloc
    max-concurrent-downloads=5
    max-connection-per-server=16
    split=16
    min-split-size=1M
    disk-cache=64M
    
    # Remote control. Inside a container aria2 must listen on all interfaces;
    # docker-compose.yml decides who can reach the port.
    enable-rpc=true
    rpc-listen-all=true
    rpc-listen-port=6800
    rpc-allow-origin-all=true
    rpc-secret=CHANGE_ME_TO_A_LONG_RANDOM_SECRET
    
    # BitTorrent. These ports must match docker-compose.yml.
    listen-port=6888
    dht-listen-port=6888
    enable-dht=true
    enable-peer-exchange=true
    seed-ratio=1.0
    dht-file-path=/config/dht.dat
    
    # Unfinished downloads survive restarts and image updates.
    input-file=/config/aria2.session
    save-session=/config/aria2.session
    save-session-interval=60
    
    # Run a script when a download finishes, and keep a log.
    on-download-complete=/config/on-complete.sh
    log=/config/aria2.log
    log-level=notice
  4. 04

    on-complete.sh

    /opt/aria2/config/on-complete.sh

    Runs after each finished download. This one writes a line to completed.log; replace it with whatever you need (move files, send a notification).

    on-complete.sh
    #!/bin/sh
    # aria2 passes: $1 = GID, $2 = number of files, $3 = path of the first file
    echo "$(date -u +%FT%TZ) finished $3 ($2 file(s), gid $1)" >> /config/completed.log

Start it

Build the image and start the container:

mkdir -p /opt/aria2/config /opt/aria2/downloadscd /opt/aria2# Save Dockerfile and docker-compose.yml here, aria2.conf and on-complete.sh in config/chmod +x config/on-complete.shdocker compose up -d --builddocker compose ps --format "{{.Name}} {{.Status}}"aria2 Up 4 seconds (health: starting)

Check that aria2 answers, with your own secret:

curl -s http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":1,"method":"aria2.getVersion","params":["token:CHANGE_ME_TO_A_LONG_RANDOM_SECRET"]}'{"id":1,"jsonrpc":"2.0","result":{"enabledFeatures":["Async DNS","BitTorrent","Firefox3 Cookie","GZip","HTTPS","Message Digest","Metalink","XML-RPC"],"version":"1.37.0"}}

Then open the online WebUI on the same computer, or any other aria2 client, and connect to port 6800 with the secret. The Alpine build has no SFTP support, which is why the feature list is one shorter than on Ubuntu.

What we tested

We ran this exact stack and checked the things that usually go wrong.

  • Restart in the middle of a download

    docker compose restart while a 50 MB download was at 7 MB. aria2 saved the session on shutdown and continued from 17.9 MB after the restart, not from zero.

  • The hook runs

    After the download, on-complete.sh wrote "finished /downloads/big.bin (1 file(s), gid …)" to /config/completed.log.

  • The healthcheck turns healthy

    docker inspect reported "healthy" after the first check, without the secret in the compose file.

  • HTTPS through nginx

    RPC calls, the browser CORS preflight and the WebSocket upgrade all passed through the nginx configuration below.

Who can reach port 6800

Inside the container aria2 must listen on all interfaces (rpc-listen-all=true), because Docker's port forwarding arrives from outside the container. Who can actually connect is decided by the ports line in docker-compose.yml:

ports entryReachable fromUse it when
"6800:6800"every network the host is onThe host sits behind a home router and you want other devices at home to connect.
"192.168.1.10:6800:6800"one network interface (use your host's LAN address)The host has a public IP as well as a LAN address.
"127.0.0.1:6800:6800"the host itself onlyA reverse proxy on the same host handles all outside access (below).

Reach it from anywhere

Two safe ways, simplest first:

  1. 01

    A VPN (WireGuard, Tailscale)

    Your phone or laptop joins your home network and connects to port 6800 as if it were at home. Nothing is exposed to the internet.

  2. 02

    An HTTPS reverse proxy

    nginx terminates TLS and forwards /jsonrpc to aria2, including WebSocket. Bind 6800 to 127.0.0.1 in docker-compose.yml, and keep a long rpc-secret: it is the password for everything. In the online WebUI, type https://aria2.example.com in the host field.

/etc/nginx/conf.d/aria2.conf
server {
    listen 443 ssl;
    server_name aria2.example.com;
    ssl_certificate     /etc/letsencrypt/live/aria2.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/aria2.example.com/privkey.pem;

    location /jsonrpc {
        proxy_pass http://127.0.0.1:6800/jsonrpc;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_read_timeout 1h;
    }
}

Use a certificate from Let's Encrypt (certbot) for your domain. Do not add basic authentication on /jsonrpc: browsers send the CORS preflight without credentials, so browser-based WebUIs would stop working.

NAS notes

We tested on Linux. On a NAS the same compose file works; only the paths and the place you paste it differ. These steps are checked, not run.

Synology (DSM 7.2 and later)

Container Manager → Project → Create. Paste docker-compose.yml and use real paths, for example /volume1/docker/aria2/config and /volume1/downloads. Put the Dockerfile in the same project folder.

QNAP

Container Station → Applications → Create, then paste the compose file. Map the folders to a shared folder.

Unraid

Use the Docker Compose Manager plugin, or create the container from the template page with the same mounts and ports.

File ownership

The container runs as root by default. If other apps (Plex, Jellyfin, *arr) must manage the files, add user: "1000:1000" (your user and group IDs) and run chown -R 1000:1000 config downloads first.

Keep it running well

Update aria2 and the base image when Alpine publishes new packages. Your config, session and downloads stay in the mounted folders:

docker compose build --pulldocker compose up -d

Keep public trackers fresh with the update script from the tracker list, pointed at the mounted config, then restart (the session is saved on shutdown, so running downloads continue):

crontab -e
0 4 * * 1 CONF=/opt/aria2/config/aria2.conf sh /opt/aria2/update-trackers.sh && docker restart aria2

To back up, copy ./config. It holds everything except the downloads themselves.

Troubleshooting

"Bind for 0.0.0.0:6800 failed: port is already allocated"

Another container or program already uses port 6800 on the host. Stop it, or publish a different host port, for example "6801:6800", and connect to 6801.

"touch: /config/aria2.session: Permission denied" and the container stops

You set user: to an account that cannot write to the config folder. Run chown -R 1000:1000 config downloads (with your IDs) on the host, or remove the user: line.

The log shows "IPv6 RPC: failed to bind TCP port 6800"

Harmless. Docker networks have no IPv6 by default, so aria2 cannot open the IPv6 socket; the line just before it says IPv4 RPC: listening on TCP port 6800, and RPC works.

The WebUI says "Disconnected"

Check docker compose ps (the container must be up), that the secret matches rpc-secret, and that you connect to the host's address, not the container's. From an HTTPS page such as aria2.org, browsers only allow localhost over plain HTTP; for anything else use the reverse proxy and an https:// address.

Torrents find no peers

Forward port 6888 for TCP and UDP on your router to the host, and add fresh trackers from the tracker list. DHT needs a few minutes to fill up the first time; its cache lives in /config/dht.dat, so later starts are quicker.

FAQ

Why build an image instead of using a ready-made one?

The Dockerfile has five instructions and uses Alpine's own aria2 package, so you can read everything that runs. Community images such as p3terx/aria2-pro add tracker updates and other scripts; they are a valid shortcut if you check their documentation.

Do I need a WebUI container?

No. The online WebUI, AriaNg or any other client talks to aria2 directly over RPC. See GUIs and extensions.

Can I change settings without rebuilding?

Yes. aria2.conf is mounted from ./config; edit it and run docker restart aria2. Only a new aria2 version needs a rebuild.

Does it work on a Raspberry Pi?

Alpine provides aria2 for ARM, so the same files build on a Pi. Use a smaller disk-cache and fewer concurrent downloads on models with little memory. We did not test on a Pi.

Related resources