I’m trying to build a rust app with rust-rocksdb as a dependency.
Using the latest rust docker image to compile and then moving the binary to a debian.
This is how my Dockerfile looks
FROM rust:1.61 as builder
RUN USER=root cargo new --bin fbrust
WORKDIR ./fbrust
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
RUN apt-get update
&& apt-get install -y ca-certificates tzdata libclang-dev
&& rm -rf /var/lib/apt/lists/*
RUN cargo build --release
RUN rm src/*.rs
ADD . ./
RUN rm ./target/release/deps/fbrust*
RUN cargo build --release
FROM debian:buster-slim
ARG APP=/usr/src/app
EXPOSE 5005
ENV TZ=Etc/UTC
APP_USER=appuser
RUN groupadd $APP_USER
&& useradd -g $APP_USER $APP_USER
&& mkdir -p ${APP}
COPY --from=builder /fbrust/target/release/fbrust ${APP}/fbrust
RUN chown -R $APP_USER:$APP_USER ${APP}
USER $APP_USER
WORKDIR ${APP}
CMD ["./fbrust"]
I’m now getting this error(s):
./fbrust: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ./fbrust)
./fbrust: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.30' not found (required by ./fbrust)
./fbrust: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./fbrust)
First of all, I’m confused why do I see both 2.29 and 2.30 required.
I checked within the container and indeed I have 2.28
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii libc-bin 2.28-10 amd64 GNU C Library: Binaries
Is there any other image I can use to achieve compatibility or can I get a hint on what dependencies/setup should I try?
2
Answers
If you look at the list of Debian releases, as of this writing Debian 10 "Buster" is one release behind, and Debian 11 "Bullseye" is the current released stable version. You can also look at the libc6 package listing and see that "Buster" contains libc6 2.28, and "Bullseye" contains libc6 2.31 (both with local patches).
So for your setup, it should work to change the final image to a newer version of Debian, like
Rust builds binaries for the host system by default; This includes the version of glibc of whatever system compiled the binary. The easiest fix is to compile the binary in another docker image using the same version of the same distro.
You should not attempt to fix this by changing distro version to match your binary; You binary will again stop working whenever you upgrage/change the distro on your personal computer (or whatever computer you’re using to build the binary).
Alternatively, you can try to compile a static binary: (related question)