Use Docker on a Xiaomi Redmi 4X

Posted by

I just got a broken Xiaomi Redmi 4X from a friend, the phone is working well but the buttons at the bottom of the phone are not responding any more. This phone has 3 different versions, it can have 2, 3 or 4GB of memory and that’s enough to use it as a server. Mine has 3GB of memory and 32GB of storage.


Required material

  • A computer with GNU/Linux
  • A micro USB Cable
  • A Redmi 4X, also named Santoni with the bootloader unlocked


Install pmbootstrap following the official guide on your GNU/Linux computer. If you don’t have it, install also git. If not specified, the commands will be run from your computer.

Postmarket OS preparation

To use Docker on our device, we will install postmarketOS on it. This system, based on Alpine Linux, is really minimalist.

Lets download the project

pmbootstrap init

For the questions

Enter to use the default Work path
Channel: edge
Vendor: xiaomi
Device codename: santoni
Enable this package: y
Username: your future username
User interface: none (no needs for a server)
Change boot partition size: n
Extra packages: none
Timezone: change it if required, else enter y
Device hostname: your device hostname
Build outdated packages: y

Replace the file ~/.local/var/pmbootstrap/cache_git/pmaports/device/testing/linux-xiaomi-santoni/config-xiaomi-santoni.aarch64 with the content of the following file:

Open the file ~/.local/var/pmbootstrap/cache_git/pmaports/device/testing/linux-xiaomi-santoni/APKBUILD and add to the build function

make ARCH="$_carch" CC="${CC:-gcc}" CFLAGS_MODULE="-fno-pic" \
       KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" modules

And to the package function:

cd "$builddir"
make ARCH="$_carch" CC="${CC:-gcc}" \
   KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" \

We will now configure pmbootstrap to enable our modifications and compile our new kernel.

pmbootstrap pkgrel_bump linux-xiaomi-santoni
pmbootstrap checksum linux-xiaomi-santoni
pmbootstrap kconfig check -f
pmbootstrap build linux-xiaomi-santoni --force

Flashing to the device

Hold volume down key and the power button to boot in Fastboot mode and plug your device to your computer.

pmbootstrap install

Lets flash our device

pmbootstrap flasher flash_rootfs
pmbootstrap flasher flash_kernel

Reboot the device

Docker installation

Connect to your device

ssh user@

Configure the WiFi network

sudo nmcli --ask dev wifi connect

Install docker, enable cgroups, add everything on startup and start the daemons

sudo apk add docker
sudo rc-update add cgroups
sudo rc-update add docker
sudo service cgroups start
sudo service docker start

We can now check if docker is working

xiaomi-santoni:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES


The system is flashed in a 3GB partition, so there is extra space that we could use. Run the following command from SSH and pick the biggest partition (/dev/mmcblk0p49 for me).

sudo fdisk -l

Format it using ext4 (don’t forget to adapt to your case)

mkfs.ext4 /dev/mmcblk0p49

Our partition is now ready, you can mount it using the /etc/fstab file, some suggestions:

  • /home
  • /var/lib/docker
  • /var/log

You can also split it and adapt the result to your use case. To extend the storage you can add a micro sd card.


We have installed postmarketOS and Docker on our phone. Tell me in the comments how you plan to use yours. On my side, it will run some basics tools and maybe an integration server for my code.

Bugs encountered:

  • It needs to be started before plugging it
  • htop is showing a load average of 4 minimum, even if only the default services are started
  • Difficult to switch off the device, I have to disconnect it from the power cable and power it off using ssh


  1. hi, I have a Xiaomi mi A1 (tissot) at the time of modifying the kernel by changing the parameters of cgroup that are in your file (.aarch64) and adding the modules to the APKBUILD the compilation fails. Any recommendation?

  2. Hello, could you show me your error?
    Maybe you could make a diff on the Santoni device and check if we have modified the same options.

  3. This blog post is awesome. Thanks for sharing. I could successfully run Docker on my old Xiaomi Mi A1. I would like to document the process that I had to follow in my blog. Would you mind if I reference this post in my blog as the one that gave me first steps to do so?

  4. when I modify the APKBUILD file
    build() {
    unset LDFLAGS
    make ARCH=”$_carch” CC=”${CC:-gcc}” CFLAGS_MODULE=”-fno-pic” \
    KBUILD_BUILD_VERSION=”$((pkgrel + 1))-postmarketOS” modules

    package() {
    downstreamkernel_package “$builddir” “$pkgdir” “$_carch” “$_flavor”
    cd “$builddir”
    unset LDFLAGS
    make ARCH=”$_carch” CC=”${CC:-gcc}” \
    KBUILD_BUILD_VERSION=”$((pkgrel + 1))-postmarketOS” \

    pmbootstrap kconfig check -f
    get an error
    [] WARNING: linux-postmarketos-qcom-sm6350/config-postmarketos-qcom-sm6350.aarch64: CONFIG_NFT_COUNTER should be set. See for details.
    [] WARNING: linux-postmarketos-stericsson/config-postmarketos-stericsson.armv7: CONFIG_NFT_COUNTER should be set. See for details.
    [] ERROR: kconfig check failed!
    [] See also:
    Run ‘pmbootstrap log’ for details.

    Can you help me?

    1. Hello,
      Are you building for the santoni device?
      In my build function, I have two commands make and you have only one.
      No problem on my side, maybe try from a fresh environment?

  5. Hello,
    thank you for your tutorial. I followed your guide, however I’m running into an issue at the end as the docker engine is stopping.

    my error massages :
    docker ps
    >>> Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

    service -v docker start
    >>> * Executing: /lib/rc/sh/ /lib/rc/sh/ /etc/init.d/docker start
    * Starting Docker Daemon …
    * supervise-daemon: fopen `/var/run/’: No such file or directory
    * Detaching to start `/usr/bin/dockerd’

    service -v docker status
    >>> * Executing: /lib/rc/sh/ /lib/rc/sh/ /etc/init.d/docker status
    * status: stopped

    I also tried podman as an alternative container engine and it tells me there is something wrong with the kernel.

    podman run hello-world
    >>>Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.
    Error: netavark: unable to append rule ‘-j NETAVARK-HOSTPORT-DNAT -m addrtype –dst-type LOCAL’ to table ‘nat’: code: 1, msg: Warning: Extension addrtype revision 0 not supported, missing kernel module?
    iptables: No chain/target/match by that name.

    Do you know how I could fix this? Or should I use an older version of Docker somehow?

  6. Hello,
    Did you recompile the kernel like explained in the tutorial?
    I will try to find my device to check if the tutorial is still working.

  7. Hello,
    I have never used lk2nd.img and the device is booting.
    @elbuho Docker is broken with the latest version, I haven’t been able to fix it for the moment

    1. sadly, mine is not booting, just stuck on mi logo. i have try to flash it on emmc and sdcard, flash boot to boot partition and recovery bit no luck. can you share your build?

Leave a Reply

Your email address will not be published. Required fields are marked *