Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@larzza
Created June 24, 2019 20:35
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save larzza/0f070a1b61c1d6a699653c9a792294be to your computer and use it in GitHub Desktop.
Save larzza/0f070a1b61c1d6a699653c9a792294be to your computer and use it in GitHub Desktop.
Install glibc in Alpine docker image
RUN apk --no-cache add \
wget \
ca-certificates \
libstdc++
# Get and install glibc for alpine
ARG APK_GLIBC_VERSION=2.29-r0
ARG APK_GLIBC_FILE="glibc-${APK_GLIBC_VERSION}.apk"
ARG APK_GLIBC_BIN_FILE="glibc-bin-${APK_GLIBC_VERSION}.apk"
ARG APK_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${APK_GLIBC_VERSION}"
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_FILE}" \
&& apk --no-cache add "${APK_GLIBC_FILE}" \
&& wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_BIN_FILE}" \
&& apk --no-cache add "${APK_GLIBC_BIN_FILE}" \
&& rm glibc-*
@jonnylink
Copy link

jonnylink commented Jun 5, 2023

This is four years old, so not shocking it doesn't work, but to anyone finding this in 2023, you'll likely get this:

#0 2.866 (1/1) Installing glibc (2.29-r0)
#0 2.867 ERROR: glibc-2.29-r0: trying to overwrite etc/nsswitch.conf owned by alpine-baselayout-data-3.4.3-r1.
#0 2.895 1 error; 18 MiB in 23 packages

The final run block just needs to be updated to:

RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
    && wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_FILE}"       \
    && apk --force-overwrite --no-cache add "${APK_GLIBC_FILE}"               \
    && wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_BIN_FILE}"   \
    && apk --no-cache add "${APK_GLIBC_BIN_FILE}"           \
    && rm glibc-*

(note the addition of --force-overwrite)

@abhijeetbhagat
Copy link

i am getting this:

[+] Building 3.3s (7/8)
 => [internal] load build definition from Dockerfile                                                                            0.0s
 => => transferring dockerfile: 37B                                                                                             0.0s
 => [internal] load .dockerignore                                                                                               0.0s
 => => transferring context: 2B                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                1.7s
 => ERROR FROM docker.io/library/build:latest                                                                                   1.4s
 => => resolve docker.io/library/build:latest                                                                                   1.4s
 => CACHED [stage-1 1/4] FROM docker.io/library/alpine:latest@sha256:82d1e9d7ed48a7523bdebc18cf6290bdb97b82302a8a9c27d4fe88594  0.0s
 => [stage-1 2/4] RUN apk --no-cache add          wget                    ca-certificates         libstdc++                     1.1s
 => CANCELED [stage-1 3/4] RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub      0.4s
------
 > FROM docker.io/library/build:latest:
------
failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_sc
ope: authorization failed

this is the relevant section from the dockerfile -

...
FROM alpine:latest
RUN apk --no-cache add  \
        wget            \
        ca-certificates \
        libstdc++
# Get and install glibc for alpine
ARG APK_GLIBC_VERSION=2.37
ARG APK_GLIBC_FILE="glibc-${APK_GLIBC_VERSION}.apk"
ARG APK_GLIBC_BIN_FILE="glibc-bin-${APK_GLIBC_VERSION}.apk"
ARG APK_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${APK_GLIBC_VERSION}"
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
    && wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_FILE}"       \
    && apk --no-cache add "${APK_GLIBC_FILE}"               \
    && wget "${APK_GLIBC_BASE_URL}/${APK_GLIBC_BIN_FILE}"   \
    && apk --no-cache add "${APK_GLIBC_BIN_FILE}"           \
    && rm glibc-*
...

@emailyc
Copy link

emailyc commented Aug 23, 2023

gcompat should provide glibc on Alpine
apk update && apk add --no-cache gcompat libstdc++

Running_glibc_programs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment