Running glibc programs

If you want to run glibc programs in Alpine Linux, there are a few ways of doing so. You can install the gcompat compatibility layer, you can install glibc alongside musl (manually, as it isn't packaged), or you could do it the easy way and use either Flatpak (the easiest), containers or a chroot.
Because there are different use cases, this is just a slight overview about what's possible and what's sensible.
= Your options =
== gcompat ==
gcompat is the go-to compatibility layer for Alpine users.
 
After that you run your binaries as normal.
== Flatpak ==
Flatpak is by far the easiest method of running any graphical glibc program on Alpine.
Firstly install it.
 
Then you can run any Flatpak application:
 
It is recommended to enable Flathub using its instructions here, as most glibc programs you might need will be packaged there.
You can then install applications from it, for example:
 
== Chroot ==
An option that's easier to generalize to other glibc applications is installing a glibc-based distribution into a chroot. You can then either chroot into it, or use a symlink and some configuration to make its glibc (and associated libraries) usable from Alpine.
After setting up a chroot using any of the methods described below, the loader can be set up in Alpine like so (these instructions are for a Debian chroot in /var/chroots/debian, on x86_64, but can be adapted to other systems by using the appropriate paths):
=== Gentoo Linux ===
Select a stage3 from here and portage latest from here at gentoo/snapshots/portage-latest.tar.xz.
First,
Enter the chroot:
And voilà, you have your working Gentoo chroot!
You can now take a look at Gentoo's Handbook to find out how you can configure and install your system, or simply extract/copy the program you need to run in your chroot enviroment and execute it.
Here is a wrapper script that is similar to arch-chroot when you frequently reuse this chroot:
Also, create an account with the same user name as host current user to the chroot or make changes to the userspec option to chroot line.
Do at chmod +x gentoo-chroot.sh to get it to work.
=== Arch Linux ===
Either use pacstrap (included with the arch-install-scripts package) or an Arch bootstrap image:
Once that is done, update the system and install the desired package(s) (denoted by "foo" in this example):
 
=== Debian ===
Use the provided debootstrap package to create the Debian chroot. --arch is optional, depending of your needs.
On the linux-grsec kernel, you will need to relax chroot limitations:
 sudo apk add debootstrap
 for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 0 | sudo tee $i; done
 mkdir ~/chroot
 sudo debootstrap --arch=i386 wheezy ~/chroot https://deb.debian.org/debian/
 for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 1 | sudo tee $i; done
 sudo chroot ~/chroot /bin/bash
You can now use apt-get to install needed packages.
== Containers ==
It's also possible to use Docker or Podman containers with a helper like Distrobox. This allows using graphical programs easily and doesn't require root privileges once set up.
=== Distrobox + Podman ===
Then set up rootless Podman, following these steps.
You'll need to mount your root as shared for Distrobox to function.
Fill in like so:
Mark it as executable.
Then autostart its service.
Finally you can create a container using your chosen image.
It may also be necessary to allow X authorization for GUI programs to work.
== Chroot + Bubblewrap ==
It's also possible to use a Debian system chroot with Bubblewrap. This allows running programs without root.
Finally we can make an alias for bwrap.
To run programs that use X11/Xorg you can use: 
In this case you might need to use xhost to allow local connections, e.g.:
Now we can invoke glibc-built binaries like so:
 or 
For updating the Chroot or installing dependencies we can mount it and then login as root:
After installing what you might want to umount the binds for dev and proc to avoid issues. 
Category:Development
Category:Installation