Running docker on Nexus 5

My Raspberry Pi 3 died. It was used for running Plex server. It was running inside docker before the Pi died. I was looking for replacement. I looked into my basement and I found two Google_Nexus_5_(lg-hammerhead) phones. Then the story began…

Prerequisites

  • you are fairly familiar with how flashing works, e.g. fastboot stuff.
  • you’ve already running postmarketos on your phone
  • you know what docker is
  • you know that you are probably gonna remove all the fancy UIs from your phone, and switch to postmarketos-ui-fbkeyboard or some console only mode
  • you’d better have a LAN connection on your phone rather than wifi

Steps

I can only prove this is working on my phones for now.

1. Edit kernel config

NOTE: before you make any change to kernel, always backup ~/.local/var/pmbootstrap/cache_git/pmaports/main/linux-postmarketos-qcom-msm8974/config-postmarketos-qcom-msm8974.armv7

Run

pmbootstrap kconfig edit postmarketos-qcom-msm8974

where qcom-msm8974 is for my Nexus 5. You need to figure out what’s for your phone.

You have 2 options to learn what to set when configuring the kernel:

You can see the changes I made to my kernel config at https://gitlab.com/tigerinus/pmaports/-/commit/d4c1ad862f5485fd9a7577e59b95e97da1b988ae

BTW – I’ve got a Ugreen USB 2.0 network adapter hooked, so I took the chance and selected

Device Drivers => Network device support => <*> USB Network Adapters => <*> ASIX AX88xxx Based USB 2.0 Ethernet Adapters 

2. Build the kernel

pmbootstrap build linux-postmarketos-qcom-msm8974 --force

I had to add --force otherwise it won’t build.

If everything is successful, you should find something like below

~/.local/var/pmbootstrap/packages/edge/armv7/linux-postmarketos-qcom-msm8974-5.9.0_rc4-r0.apk

3. Install the kernel

Get the linux-postmarketos-qcom-msm8974-5.9.0_rc4-r0.apk copied onto your phone and do

sudo apk add -u linux-postmarketos-qcom-msm8974-5.9.0_rc4-r0.apk

Just in case, I also copied /boot/boot.img-postmarketos-qcom-msm8974 to local as boot.img, boot to bootloader and did

fastboot flash boot boot.img

Reboot the phone and run check-config.sh again to see if anything missing. My experience is you don’t need everything enabled.

4. Install docker

Boot to your phone, assuming you have a pretty good internet connection, then do

sudo apk add docker

Not only this installs docker, but also an important service containerd.

5. Get docker daemon running

Run

sudo service docker start

We are not there yet. This first-time boot is for creating files, directories, group it needs. The docker command won’t work because of couple things that have to happen at boot time below.

DO NOT make docker to start on boot or you will get “can’t load program: function not implemented: unknown.” error.

BTW – If you hate doing sudo docker... everytime, you can optionally add yourself to docker group by

sudo vi /etc/group

Now reboot so at least containerd service is effective, in terms of automatically mounting cgroup2 to /sys/fs/cgroup.

sudo reboot

After reboot, do

sudo service docker start

You should see something like

Sudo service docker start.png

which you won’t see if you tried to start docker service before the reboot.

6. Verify things are good

Docker info.png
health check
Docker run hello world.png
hello-world
Docker run fedora.png
fedora

What’s next?

It’d be fun to have kubernetes running on this little device. Not sure if I should go with k3s or microk8s.

References

在 k8s 中开一个 shell

经常需要一个远程临时的 shell 做些什么事,比如实验一下某个需要运行一晚上的脚本,用完环境就扔了。在 AWS 或者 Azure 上开一个新的 VM 总是感觉不够快捷,也不想专门浪费一个 VM 的资源为这个目的留着。

还好我有个 Kubernetes 下创建 pod 的权限,这下就方便多了。

首先创建一个 shell.yaml 来描述一个可以运行 bash shell 的 pod(容器镜像用的是官方的 bash 镜像):

apiVersion: v1
kind: Pod
metadata:
  name: shell
  labels:
    purpose: shell
spec:
  containers:
  - name: shell
    image: bash
    command: ["tail"]
    args: ["-f", "/dev/null"]
  restartPolicy: OnFailure

然后执行下面的命令来创建这个 pod:

$ kubectl apply -f shell.yaml
pod/shell created

成功之后,就可以通过下面的命令获得一个远程的 shell 环境了:

$ kubectl exec -it shell -- bash --login
shell:/#

这个新创建的环境是基于 alpine linux 的,自然什么工具都没有自带。需要什么工具,只要用 apk add 命令安装就好了。我因为工作需要一般都会安装下面这些工具:

apk add git
apk add nodejs-current
apk add npm
apk add python3

如果想从或者向这个 pod/shell 复制文件的话,用下面的命令就好了:

kubectl cp ... ...