To run a small Docker image like Alpine in Termux using udocker (a user-space Docker alternative without root or a daemon), execute the following commands sequentially in your Termux shell. This setup handles installation, pulling the lightweight Alpine image (~5MB), and running a simple container. Note that you'll need to set an environment variable each session for proot support.
pkg update && pkg upgrade -y
pkg install -y python-pip proot
pip install udocker
udocker --debug install --force
export UDOCKER_USE_PROOT_EXECUTABLE=$(command -v proot)
udocker pull alpine
This downloads the alpine:latest image to your user space (stored in ~/.udocker).
udocker run --rm alpine echo "Hello from Alpine container!"
This creates and runs a temporary container, printing the message. The --rm flag removes it after execution. You can replace echo "Hello from Alpine container!" with other commands, like ls or cat /etc/os-release to inspect the image.
- udocker uses proot for emulation in Termux, so it's suitable for lightweight tasks but may have performance limitations on mobile hardware.
- If you want to create a named container for reuse:
udocker create --name=myalpine alpinefollowed byudocker run --rm myalpine. - To make the export persistent, add it to
~/.bashrcor~/.profile:echo 'export UDOCKER_USE_PROOT_EXECUTABLE=$(command -v proot)' >> ~/.bashrcand thensource ~/.bashrc. - For more details, refer to the udocker user manual.
Comprehensive udocker Commands for Termux (Alpine Image)
Below is a comprehensive list of practical udocker commands for managing and using the Alpine image in Termux. These assume udocker is installed, the proot executable is set (
export UDOCKER_USE_PROOT_EXECUTABLE=$(command -v proot)), and the Alpine image is pulled (udocker pull alpine). All commands are run in the Termux shell. This list includes previously provided commands (corrected where needed) and additional ones for a complete reference, tailored to Alpine where applicable, based on official udocker documentation.1. Run a temporary container
Executes a command in a temporary Alpine container and removes it after.
2. Create a named container
Creates a persistent container named
myalpinefor reuse.3. Run a command in a named container
Runs
ls -l /etcin themyalpinecontainer, listing files in/etc.4. Start an interactive shell
Opens an interactive shell in a temporary Alpine container (
/bin/shis Alpine’s default shell).5. List all containers
Shows all created containers, including names and statuses.
6. List available images
Displays downloaded images, including
alpine:latest.7. Inspect container details
Shows configuration and metadata for the
myalpinecontainer.8. Remove a container
Deletes the
myalpinecontainer.9. Remove an image
Deletes the Alpine image from
~/.udocker.10. Copy files into a container
Copies
myfile.txtfrom the host to/tmp/myfile.txtin themyalpinecontainer.11. Copy files from a container
Copies
/etc/os-releasefrom themyalpinecontainer to the host’s current directory.12. Run a container with a volume mount
Mounts the current directory’s
localsubdirectory as/mntin a temporary container and lists its contents.13. Check Alpine version
Displays the Alpine version by reading
/etc/os-release.14. Install a package in a container
Installs the
nanoeditor in a temporary Alpine container (changes are not persistent).15. Export a container to a tar file
Saves the
myalpinecontainer’s filesystem tomyalpine.tar.16. Search for images on Docker Hub
Searches Docker Hub for Alpine-related images and lists matching repositories.
17. List tags for an image
Displays available tags (versions) for the Alpine image, like
latest,3.18, etc.18. Pull an image for a specific platform
Pulls the Alpine image for ARM64 architecture (useful on ARM-based Android devices).
19. List images with long format
Lists downloaded images in long format, showing details like image ID, creation date, and size.
20. Create a container with a custom name
Creates a new persistent container named
myalpine2from the Alpine image.21. Run with an empty entrypoint
Overrides the default entrypoint to run a custom shell command, listing the root directory.
22. Run as a specific user
Runs the container as the
rootuser and prints the current user identity.23. List containers with details
Lists all containers with mount points (
-m) and sizes (-s) for more verbose output.24. Assign a name to a container ID
Assigns the name
mynamedalpineto an existing container by its ID (get ID fromudocker ps).25. Rename a container
Changes the name of the
myalpinecontainer tomyalpine-renamed.26. Clone a container
Creates a duplicate of the
myalpinecontainer with a new ID (name it afterward if needed).27. Tag an image
Creates a new tag
mycustom:alpine-v1pointing to the existing Alpine image.28. Import an image from a tar file
Imports a tar file (
alpine-imported.tar) as a new image taggedalpine:imported(create the tar via export first).29. Commit changes to a new image
Saves changes made to the
myalpinecontainer (e.g., after installing packages) as a new imagealpine:modified.30. Run with environment variables
Sets an environment variable
MY_VARin the container and prints it usingenv.31. Verify an image
Checks the integrity of the Alpine image’s metadata and files.
32. Run with a specific working directory
Sets the working directory to
/tmpand prints it, confirming the container’s current directory.33. Update an image
Forces a re-pull of the Alpine image to update it to the latest version.
34. Execute a command in an existing container
Executes
ls /tmpin the running or stoppedmyalpinecontainer (if it exists).35. Save an image to a tar file
Exports the Alpine image (not a container) to
alpine-image.tarfor backup or transfer.36. Load an image from a tar file
Imports an image from
alpine-image.tarinto udocker’s repository.37. Run with a specific hostname
Sets the container’s hostname to
myhostand prints it (--hostenvallows host environment passthrough).38. Display udocker version
Shows the installed udocker version.
39. Check container logs
Displays logs for the
myalpinecontainer (useful if commands produce output).40. Run with a bind mount
Binds the host’s home directory to the container’s
/rootand lists its contents.Notes
--rmfor temporary containers to save space; omit for persistent containers unless cleaning up.-itflag enables interactive mode with a TTY (essential for shells like/bin/sh).-v) and bind mounts (--bindhome) allow file sharing but may have path resolution issues in proot mode; use absolute paths if errors occur.--user=rootfor privileged operations likeapk addin Alpine.udocker commit) or exporting/importing.udocker --helpor consult the udocker user manual for advanced options.--platform=linux/arm64), verify your device’s architecture withuname -m.