Is there a best practice on setting up glibc on docker alpine linux base image?

DockerGlibcAlpine

Docker Problem Overview


Is there a best practice on setting up glibc on docker alpine linux base image with correct paths so any spawned process can correctly reference the location of the installed libc libraries?

Docker Solutions


Solution 1 - Docker

Yes there is,

I've used a custom built glibc to install a JRE on it.

You can find it here

You can use wget or curl to get the code and apk to install them

UPDATED commands see comments below

apk --no-cache add ca-certificates wget
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
apk add glibc-2.28-r0.apk

It worked perfectly for me

Solution 2 - Docker

Installing the glibc compatibility libraries has worked for me so far every time

apk add gcompat

https://pkgs.alpinelinux.org/package/edge/community/x86_64/gcompat

Solution 3 - Docker

The best practice is to not install glibc on Alpine Linux. It uses musl libc instead, a lightweight, fast, simple and standards-conform C library (i.e. everything that glibc is not).

Instead of installing glibc on Alpine, build and/or package your dependent software packages and libraries for Alpine.

    FROM alpine:3.4
    RUN echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main" > /etc/apk/repositories
    RUN echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories
    RUN apk --no-cache --update-cache add gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev
    RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
    RUN pip install numpy scipy pandas matplotlib

Solution 4 - Docker

I had create a github repo Docker build for glibc for alpine, support multi-arch, i.e. x86_64, aarch64, etc. You can build from the latest glibc source for any CPU type in just one line command. It was forked from sgerrand's repo, I modified to support multi-arch and combine builder stage and packaging stage into one single line. Or you could just download the pre-built packages from release page.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkaiView Question on Stackoverflow
Solution 1 - DockercarlomasView Answer on Stackoverflow
Solution 2 - DockersecustorView Answer on Stackoverflow
Solution 3 - DockerJakub JirutkaView Answer on Stackoverflow
Solution 4 - DockerPuxosView Answer on Stackoverflow