banner
云野阁

云野阁

闲云野鹤,八方逍遥

Installing Docker on Android Phones

Installing Docker on Android Phones Using ALPINE-TERM#

Alpine Term is an Android application based on Termux, which integrates QEMU virtual machine and Alpine Linux, allowing a complete Linux environment to run on Android phones without root access, and enabling the direct use of container technologies like Docker.

Environment Requirements#

The phone's system environment must meet the following:

  • AArch64 architecture (generally the case)
  • Android 7.0+
  • At least 500 MB of space on internal storage.
  • Internet connection

Installing Alpine Term#

(1) Download the ALPINE-TERM APK (606MB) from GitHub.

Download link: https://github.com/FakeRajbhx/alpine-term/releases/download/New/alpine-term-v16.0-release.apk

(2) After installation on the phone, open the app and wait for the system to load completely.

(3) Enter the default user alpine and password alpine to log in to the system.

(4) Switch to the root account; the default password for the root user is alpine. You can change it by entering passwd.

# Switch to root command line
sudo -s

(4) Modify the sshd service configuration file to enable SSH remote connection.

vi /etc/ssh/sshd_config
# Allow root user to connect and log in
PermitRootLogin yes
# Enable password login
PasswordAuthentication yes

# Restart sshd service
service sshd restart

(5) In the ALPINE-TERM terminal interface, swipe right to bring up the terminal menu, select [1] QEMU, enter the following command, and press Enter to open the SSH remote connection port.

# Map port 22 to the phone's port 8034
hostfwd_add tcp::8034-:22

1

You need to enter this command every time you start ALPINE-TERM to establish a remote connection.

(6) Modify the software repository source.

# Remove the original software repository source
mv /etc/apk/repositories /etc/apk/repositories.bak
# Use Tsinghua source
echo "
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.13/main
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.13/community
" > /etc/apk/repositories 

(7) Modify DNS.

sed -i 's/nameserver 94.16.114.254/nameserver 114.114.114.114/g' /etc/resolv.conf 
sed -i 's/nameserver 185.120.22.15/nameserver 223.5.5.5/g' /etc/resolv.conf

Installing Docker#

(1) Update the software packages.

apk update  && apk upgrade --force-broken-world

(2) The system comes with Docker, but not Docker Compose.

# Set to start on boot
rc-update add docker boot
# Start Docker
service docker start
# Check version
docker version

[Optional] Change the software repository source, uninstall the system-installed Docker, and install the new version of Docker and Docker Compose.

echo "
https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main
https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/community
" > /etc/apk/repositories 
# Update
apk update 

# Uninstall Docker
apk del docker --force-broken-world
# Install the new version of Docker and Docker Compose
apk add docker docker-compose  docker-cli-compose --force-broken-world

(3) Configure domestic mirror sources and modify the default storage directory for Docker.

echo '{
  "data-root": "/data/dockerData",
  "registry-mirrors": ["https://docker.1ms.run"]
}' > /etc/docker/daemon.json

(4) Start Docker and set it to start on boot.

# Restart Docker
service docker restart
# Set to start on boot
rc-update add docker boot
# Check version
docker version
docker compose version

Testing Access#

(1) Create an Nginx container.

# Pull the Nginx image and create a container, mapping the host's port 8080
docker run -itd --name=nginx -p 8080:80 nginx
# Check running containers
docker ps

If an error occurs when starting the container, restart the Alpine host.

docker: Error response from daemon: failed to create endpoint nginx on network bridge: failed to add the host (veth3f2f206) <=> sandbox (veth9a8264a) pair interfaces: operation not supported.

(2) Configure the corresponding port in QEMU.

# Map the host's port 8080 to the phone's port 8081
hostfwd_add tcp::8081-:8080

Similar to SSH mapping, when mapping container ports, you also need to execute in QEMU:

hostfwd_add tcp::phone port- port

(3) Access by entering ip+port in the browser.

2

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.