Can docker solve a problem of mismatched C shared libraries?
Asked Answered
D

1

8

I am trying to run some haskell code on an ubuntu (18.04) host, which was compiled on my laptop.

host: 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

laptop: 4.14.74-1-MANJARO #1 SMP PREEMPT Fri Oct 5 14:16:52 UTC 2018 x86_64 GNU/Linux

The error I get is

/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found

After doing some research I learned that this is because my laptop has version 2.28 of glibc installed, but the host only has libc6 2.27.

I did some googling and figured that maybe docker could solve this problem. However, I just created a docker image with the following Dockerfile and it didn't work (same GLIBC_2.28 error)

FROM fpco/stack-build:lts-12.9 as builder

RUN mkdir /opt/build
COPY . /opt/build
RUN cd /opt/build && stack build 

FROM ubuntu:18.04
RUN mkdir -p /opt/myapp
WORKDIR /opt/myapp
RUN apt-get update && apt-get install -y \
  ca-certificates
COPY --from=builder /opt/build/.stack-work/install/x86_64-linux-tinfo6/lts-12.9/8.4.3/bin .
CMD ["/opt/myapp/myapp-exe"]

I'm not sure what to do now. I have a few questions:

  • Why am I getting this problem in the first place? I thought I read somewhere that glibc is backwards compatible? (Is glibc the same thing as libc6..?)

  • Is there a way to use docker to get around this problem? Could i run my build process inside an ubuntu image? e.g. FROM fcpo/stack-build:lts-12.9 and ubutu:18.04, then later on creating another ubuntu image into which i copy my binary?

  • Has anybody else run into this before ? If so did you find a solution (other than just changing operating system?)?

Disregardful answered 15/10, 2018 at 19:12 Comment(4)
Adding another layer of complexity is unlikely to simplify your problem. Can you rebuild your program in the new environment or run it remotely?Gibun
I would rather do the compilation on my machine because the host is slow (not helped by stack taking a long time to compile all the dependencies), and I have limited bandwidth. But yes ideally I would have a machine which did have such an up to date version of glibc... I just wondered if anybody else had had this issue and solved itDisregardful
It can solve this problem yes. Are you sure your docker image has glibc 2.28? But can you not just update glibc on the host?Avionics
Just clearing up confusion: glibc 2 = libc6. glibc being backwards compatible means that newer glibc supports programs built for older glibc. You need glibc to be forwards compatible to get a program built on later glibc to work with older glibc; it is not.Edwin
P
4

Why am I getting this problem in the first place? I thought I read somewhere that glibc is backwards compatible?

GLIBC is backwards compatible (programs built against old GLIBC continue to work on newer GLIBC), but the inverse is not true.

In your case, you built on a newer (GLIBC-2.28) system, and are trying to run on an older one (GLIBC-2.27). That is not guaranteed to work (although it might for sufficiently simple programs).

Is there a way to use docker to get around this problem?

You need to build against the oldest version of GLIBC that you are planning to use.

You can achieve this in multiple ways:

  • use a Linux to older Linux crosscompiler
  • use a chroot build environment
  • use a docker container with older GLIBC at build time.

Or you could run in a docker container that has the GLIBC-2.28 that your program needs.

Psalmody answered 16/10, 2018 at 3:26 Comment(2)
thanks! i feel a bit dumb about the backwards compatibility now... I have realised that I can try doing FROM ubuntu:18.04 $do build$, FROM ubuntu:18.04 $copy executables$Disregardful
hmm just looked and the image fpco/stack-build:lts-12.9 uses ubuntu 16.04 (which has glibc < 2.28) which implies that the docker container must be using the shared C libraries from my laptop rather than the ubuntu image (otherwise it would have 'just worked')? nonetheless i will try it with ubuntu 18.04 laterDisregardful

© 2022 - 2024 — McMap. All rights reserved.