Skip to main content

Running Docker natively on a smartphone

Introduction
#

A few years ago, my old OnePlus 6T got discontinued because OnePlus decided it wasn’t getting any security updates anymore. Truly a waste, because there was nothing wrong with the hardware. I threw it in a drawer after buying a new (second hand) phone and never touched it again. Until recently.

This video by Hardware Haven shows it’s possible to install a version of Linux on a select number of phones. By sheer luck, the linux distribution in question, PostmarketOS, officially supports the OnePlus 6T. I used an old MacBook with Linux Mint installed as my installation machine.

Installation steps
#

The first step is to unlock the bootloader. This allows a custom operating system to be flashed later. First, install the android-tools package, containing the necessary unlocking and flashing binaries. Connect the phone via USB. Enable developer mode in the Android settings and turn on USB debugging. Restart the phone into flash mode and the bootloader can be unlocked by running

fastboot oem unlock

I had some permission-related issues and ended up having to run the fastboot command as sudo.

Next, download a pre-built PostmarketOS image with a user interface of choice. I picked GNOME as it looked pretty sleek. The official installation guide explains we can flash the image using

fastboot erase dtbo
fastboot flash boot [the file that ends in -boot.img]
fastboot flash userdata [the other file]
fastboot reboot

The phone will now restart and boot into PostmarketOS. The default username and password are user and 147147 respectively.

The flash mode screen, allowing the bootloader to be unlocked.
The flash mode screen, allowing the bootloader to be unlocked.
Booting screen of PostmarketOS
Booting screen of PostmarketOS
The home screen of PostmarketOS with GNOME.
The home screen of PostmarketOS with GNOME.
Running `htop`, showing 8GB of memory and 8 threads.
Running htop, showing 8GB of memory and 8 threads.

The thought of using PostmarketOS as a daily driver does not appeal to me, though. The OS is slow, cluncky and contains bugs. However, that’s not why we’re here! We’re here to run services with Docker.

SSH
#

As I’m going to install software through the command line, SSH access would be nice to have. First start the SSH daemon and then enable the service on every boot

sudo systemctl start sshd
sudo systemctl enable sshd

Make sure the device is unplugged and run ip -a to get the devices’ IP address. Now we can ssh in with username and password

Installing Docker and NGINX
#

As PostmarketOS is a version of Alpine, it uses the apk package manager. To install Docker, run

apk add docker

Optionally, you can choose to enable the docker service at start up.

To prove Docker is working, we’ll first run an NGINX container with

docker run -p 8080:80 nginx

and then browse to the phone’s ip address on port 8080 in a browser. We’re greeted with the default NGINX page, proving NGINX is working properly.

The result of browsing to the phones' ip address on port 8080 in a browser.
The result of browsing to the phones’ ip address on port 8080 in a browser.