indigo-dc / udocker

A basic user tool to execute simple docker containers in batch or interactive systems without root privileges.
https://indigo-dc.github.io/udocker/
Apache License 2.0
1.38k stars 135 forks source link

Error running on Android (Termux) #424

Open luisdavim opened 7 months ago

luisdavim commented 7 months ago

I'm getting the folloing error:

$ udocker run quay.io/giantswarm/debug
Info: downloading layer sha256:670ede3d39ae57d0ad8cfd9c6d21e31eb2e394def3f7bb5b5a3a00d0cfa1e394
Info: downloading layer sha256:750ce8d28ced8a50b02aa7c1735bb3973065495b9eefbd3f18a5f1c0b50516ab
Info: downloading layer sha256:0d00e96b2dbce65991da53bc5fe08b761f9d767c89e6e1c36ca0b7bcf6c5bd49
Info: downloading layer sha256:7597eaba0060104f2bd4f3c46f0050fcf6df83066870767af41c2d7696bb33b2
Error: while extracting image layer
Error: creating container: 76367a60-0d79-3f79-a0cb-bee9025af8d4

 ******************************************************************************
 *                                                                            *
 *               STARTING 76367a60-0d79-3f79-a0cb-bee9025af8d4                *
 *                                                                            *
 ******************************************************************************
 executing: sh
proot error: 'qemu-x86_64' not found (root = (null), cwd = /data/data/com.termux/files/home, $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
fatal error: see `proot-arm64-4_8_0 --help`.
$ type qemu-x86_64
qemu-x86_64 is /data/data/com.termux/files/usr/bin/qemu-x86_64

though I do have booth qemu-system and qemu-user installed.

I've tryed setting root_path but that doesn't seem to have any effect:

$ cat ~/.udocker/udocker.conf
[DEFAULT]
root_path = /data/data/com.termux/files/home/.theme.sh/bin:/data/data/com.termux/files/home/.local/bin:/data/data/com.termux/files/home/.kitty-tmux:/data/data/com.termux/files/home/.cargo/bin:/data/data/com.termux/files/home/.krew/bin:/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/home/go/bin
George-Seven commented 7 months ago

Error: while extracting image layer

Apply this fix for udocker to extract images properly in Android environment -

https://github.com/George-Seven/gpt4free-Termux/blob/20d4dca3b28ee7495e3bcfc00c7d94aafbfe7efd/g4f.sh#L65-L83

# 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}"


'qemu-x86_64' not found

Apply this fix for udocker so that it finds qemu -

# Fix qemu not found errors that occurs when running non-native platform containers
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}"

https://github.com/George-Seven/gpt4free-Termux/blob/20d4dca3b28ee7495e3bcfc00c7d94aafbfe7efd/g4f.sh#L89-L104


fatal error: see proot-arm64-4_8_0

You should use proot provided by Termux.The one provided by udocker doesn't work properly -

https://github.com/George-Seven/gpt4free-Termux/blob/20d4dca3b28ee7495e3bcfc00c7d94aafbfe7efd/g4f.sh#L449-L458

# Force use Termux provided proot
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 = 3
EOF
echo "2.9.9" > "${HOME}/.udocker/lib/VERSION"
# Create dummy VERSION to suppress redundant download of Android-incompatible udockertools
# https://github.com/indigo-dc/udocker/issues/376#issuecomment-1300626183
luisdavim commented 7 months ago

Thanks, I'll give this a try. Is there a way udocker could detect that it's in Termux and use different paths?

Maybe by checking if ${PREFIX} is set and/or checking ${OSTYPE}, or uname -o

$ echo $OSTYPE
linux-android

$ uname -o
Android