Last active
December 20, 2024 17:40
-
-
Save George-Seven/cbeec25874b34aa824c7ea9b3af3e129 to your computer and use it in GitHub Desktop.
udocker for Termux, with patches applied to fix it. Now you can use it in Android too. udocker allows running docker images without root/custom kernels - https://github.com/indigo-dc/udocker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/data/com.termux/files/usr/bin/bash | |
install_udocker(){ | |
apt update | |
yes | pkg install -y python-pip patch proot | |
if pip freeze | grep -Eq "^udocker=="; then | |
pip uninstall -y udocker | |
fi | |
pip install -U udocker | |
} | |
fix_udocker(){ | |
fix_udocker_conf(){ | |
mkdir -p "${HOME}/.udocker/lib" | |
cat <<'EOF' > "${HOME}/.udocker/udocker.conf" | |
[DEFAULT] | |
use_proot_executable = /data/data/com.termux/files/usr/bin/proot | |
proot_link2symlink = True | |
verbose_level = 1 | |
EOF | |
echo "2.9.9" > "${HOME}/.udocker/lib/VERSION" | |
} | |
fix_udocker_hardlinks(){ | |
# Fix errors when extracting hardlinks from Docker images | |
# https://github.com/indigo-dc/udocker/issues/388#issuecomment-1527277800 | |
UDOCKER_PATCH=' | |
--- udocker/container/structure.py | |
+++ udocker.mod/container/structure.py | |
@@ -281,7 +281,7 @@ | |
if Msg.level >= Msg.VER: | |
verbose = '\'v'\'' | |
Msg().out("Info: extracting:", tarf, l=Msg.INF) | |
- cmd = ["tar", "-C", destdir, "-x" + verbose, | |
+ cmd = ["proot", "--link2symlink", "tar", "-C", destdir, "-x" + verbose, | |
"--one-file-system", "--no-same-owner", "--overwrite", | |
"--exclude=dev/*", "--exclude=etc/udev/devices/*", | |
"--no-same-permissions", r"--exclude=.wh.*", | |
' | |
TMP_PATCH_FILE="$(mktemp)" | |
patch -p0 --no-backup-if-mismatch -r "${TMP_PATCH_FILE}" -d "$(python -c "import sysconfig; print(sysconfig.get_path('platlib'))" 2>/dev/null || echo "${PREFIX}/lib/python3.11/site-packages")" 2>/dev/null >/dev/null <<< "${UDOCKER_PATCH}" || true | |
rm -rf "${TMP_PATCH_FILE}" | |
return 0 | |
} | |
fix_udocker_qemu(){ | |
# Fix qemu not found errors that occurs when running non-native platform containers | |
# Not needed for g4f container, but helpful for your other platform containers if any | |
UDOCKER_PATCH=' | |
--- udocker/engine/base.py | |
+++ udocker.mod/engine/base.py | |
@@ -690,4 +690,4 @@ | |
if not qemu_path: | |
Msg().err("Warning: qemu required but not available", l=Msg.WAR) | |
return "" | |
- return qemu_path if return_path else qemu_filename | |
+ return qemu_path if return_path else qemu_path | |
' | |
TMP_PATCH_FILE="$(mktemp)" | |
patch -p0 --no-backup-if-mismatch -r "${TMP_PATCH_FILE}" -d "$(python -c "import sysconfig; print(sysconfig.get_path('platlib'))" 2>/dev/null || echo "${PREFIX}/lib/python3.11/site-packages")" 2>/dev/null >/dev/null <<< "${UDOCKER_PATCH}" || true | |
rm -rf "${TMP_PATCH_FILE}" | |
return 0 | |
} | |
fix_udocker_proot(){ | |
# Fix shm errors | |
# https://github.com/termux/proot-distro/issues/19 | |
# Fix hardcoded bad port errors | |
#https://github.com/termux/proot-distro/issues/22 | |
UDOCKER_PATCH=' | |
--- udocker/engine/proot.py | |
+++ udocker.mod/engine/proot.py | |
@@ -166,7 +166,7 @@ | |
if (Config.conf['proot_link2symlink'] and | |
self._has_option("--link2symlink")): | |
- proot_link2symlink = ["--link2symlink", ] | |
+ proot_link2symlink = ["--link2symlink", "--sysvipc", "-L", "-p", ] | |
else: | |
proot_link2symlink = [] | |
' | |
TMP_PATCH_FILE="$(mktemp)" | |
patch -p0 --no-backup-if-mismatch -r "${TMP_PATCH_FILE}" -d "$(python -c "import sysconfig; print(sysconfig.get_path('platlib'))" 2>/dev/null || echo "${PREFIX}/lib/python3.11/site-packages")" 2>/dev/null >/dev/null <<< "${UDOCKER_PATCH}" || true | |
rm -rf "${TMP_PATCH_FILE}" | |
return 0 | |
} | |
fix_udocker_conf | |
fix_udocker_hardlinks | |
fix_udocker_qemu | |
fix_udocker_proot | |
} | |
install_udocker | |
fix_udocker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Patches taken from my discussion here - indigo-dc/udocker#424 (comment)