77

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?

kai
  • 817
  • 1
  • 6
  • 8
  • 4
    The Alpine docks have a whole page dedicated to this... https://wiki.alpinelinux.org/wiki/Running_glibc_programs – bremen_matt Apr 04 '19 at 04:30

6 Answers6

60

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

carlomas
  • 1,032
  • 1
  • 11
  • 14
  • 1
    The updated commands are based on latest install instructions from https://github.com/sgerrand/alpine-pkg-glibc - these worked well – RichVel Mar 25 '21 at 18:12
24

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

secustor
  • 3,001
  • 2
  • 14
  • 20
4

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
Erik Aronesty
  • 11,620
  • 5
  • 64
  • 44
Jakub Jirutka
  • 10,269
  • 4
  • 42
  • 35
  • 25
    Because there is no good alternative. Java, python, node and other frameworks need glibc, musl is not supported (or not really). So either use use a big base image, or you use alpine with ported glibc – FreshMike Jun 22 '18 at 10:41
  • 26
    Using musl_libc is like Jeff Bezos saying that from now on Amazon will only do business in Latin. – Alwyn Schoeman Oct 11 '18 at 17:22
  • " a lightweight, fast, simple " nope. it's surely not fast - that's the reason i want replace it – Johannes Reiners Jun 02 '23 at 11:20
2

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.

Puxos
  • 21
  • 1
  • when I run it I get ```E: The repository 'http://mirrors.aliyun.com/ubuntu disco Release' does not have a Release file. E: The repository 'http://mirrors.aliyun.com/ubuntu disco-security Release' does not have a Release file. E: The repository 'http://mirrors.aliyun.com/ubuntu disco-updates Release' does not have a Release file. E: The repository 'http://mirrors.aliyun.com/ubuntu disco-backports Release' does not have a Release file. E: The repository 'http://mirrors.aliyun.com/ubuntu disco-proposed Release' does not have a Release file.``` – Michaela Ervin Nov 16 '20 at 04:57
1

Use below

RUN apk add --no-cache gcompat libstdc++
buddemat
  • 4,552
  • 14
  • 29
  • 49
  • 1
    While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Shawn Hemelstrand Jan 25 '23 at 02:13
  • Alpine Linux uses musl libc, a lightweight, fast, simple and standards-conform C library. To run glibc compiled apps in Alpine we should add two libs provided. RUN apk add --no-cache gcompat libstdc++ – Basa Deva Reddy Jan 25 '23 at 08:18
  • Could you please edit that into your answer instead? – Shawn Hemelstrand Jan 25 '23 at 08:35
0

To piggyback off of carlomas' answer, downloading and installing from the repo is the way to go. But on newer versions of Alpine it will throw when installing glibc due to a clash with alpine-baselayout. For more context, see this issue.

The current workaround for that is to force an override when installing glibc. You can add the flag like this:

apk --no-cache add --force-overwrite glibc-<GLIBC_VER>.apk

Followed by a reinstall of the package it clashes with:

apk add --force-overwrite alpine-baselayout-data

This should solve the ERROR: glibc-<GLIBC_VER>: trying to overwrite etc/nsswitch.conf owned by alpine-baselayout-data-<BASELAYOUT_VER>. error you might see.

fourjuaneight
  • 57
  • 1
  • 7