Setup docker in Rpi 3 and build docker image for aria2

0. Objective

I want to install aria2 and its webui, and expose it to the Internet, so that I can make my Rpi as a remote downloader.

Here is how I install the Docker on raspbian and build the webui-aria2 docker image.

1. Install Docker for on Raspbian Jessie

The installation process refers to these two posts, thanks to the authors:

  1. umiddelb's wiki on Github
  2. hypriot/rpi-docker-builder

For me, I just need to run the following commands:

$ curl -sSL >/tmp/docker-hypriot_1.8.1-1_armhf.deb
$ sudo dpkg -i /tmp/docker-hypriot_1.8.1-1_armhf.deb
$ rm -f /tmp/docker-hypriot_1.8.1-1_armhf.deb
$ sudo sh -c 'usermod -aG docker $SUDO_USER'
$ sudo systemctl enable docker.service

And it's done.

2. Download the webui

$ wget
$ unzip

3. Write the configuration file for aria2

There is no need to download aria2 in the Raspberry, because it will be downloaded in the docker image later.

But I need to write a configuration file for aria2. In the folder of the webui, create the configuration file and session file for aria2:

$ touch aria2.session
$ vim aria2.conf

Add the following lines in aria2.conf:

# Enable rpc
# Allow all origin which is needed for cross-origin web UI
# Allow access from the Internet
# default RPC port
# It's recommanded to use: 3
# Enable continue but need to make the session file
# It's recommanded to use: 3
# Minimun split size, important to small files
# For single file. It's recommanded to use: 5
# No limit when zero
# It is recommanded to preallocate

#########Change the following#########
# Path to put your downloads
# Path to the input file, useful when need to save the session and continue downloading.
# When disconnected, it will read the latest session. Here uses 60s.

Notice that the aria2.session and aria2.session should be in the same folder of the webui folder, because they will be added to the image in the following Dockerfile.

4. Write the Dockerfile

Note that the Dockerfile in the is not suitable to raspbian, because it uses gosu and goreman to run the http service. But it will cause Exec format error problem when running the container.

So it is necessary to build a new Dockerfile with the Raspbian image and user common tools to setup the http service. Possible solutions like Python or Nginx (actually I just know these two), which will not be provided in a clean Raspbian docker image.

Here I choose to use Nginx.

In the folder of webui-aria2, replace the content in the Dockerfile with the following:

# Use rpi-raspbian as basic image
FROM sdhibit/rpi-raspbian

# Update the repository
RUN apt-get update \
        && apt-get install -y aria2 nginx \
        && rm -rf /var/lib/apt/lists/*

# Prepare conf file
RUN mkdir /data -p \
        && mkdir /aria2c -p
ADD aria2.session /aria2c/
ADD aria2.conf /aria2c/
ADD . /var/www/html/

# Expose ports
EXPOSE 6800 80

# Set the default command to execute when creating a new container
CMD service nginx restart && aria2c --conf-path=/aria2c/aria2.conf

Need to change: nothing.

5. Build the docker image

Now it is ready to build the image. In the folder of the Dockerfile:

$ sudo docker build -t pi-webui-aria2 .

When it's all done, run the container:

sudo docker run -d -v /Downloads:/data -p 6800:6800 -p 9100:80 --name="webui-aria2" pi-webui-aria2

Need to change:

  1. Folder to put the downloaded files in Rpi (I would choose to put it in a huge disk): /Downloads,
  2. Port to visit the webui: 9100.

It will be available at http://localhost:9100.

6. Expose the aria2 to the Internet

If I cannot visit the webui-aria2 from the Internet, it will be meaningless to do all the previous things. "I want it to work while I'm not at home."

Here is how to expose the webui-aria2 to the Internet:

Use the method in this post to expose the ports 9100 and 6800 of Rpi. Just need to change the pi3_port to 9100 and 6800.