Release binary not working in docker

This is my docker file

FROM rust

COPY target/release/chola /bin/chola

CMD ["bin/chola"]

I'm getting this error after running the container

docker run -it --rm schoolboy/chola-nightly
bin/chola: /lib/x86_64-linux-gnu/ version `GLIBC_2.29' not found (required by bin/chola)

[quote="sch00lb0y, post:1, topic:36383"]
[/quote]Search for “install glibc_2.29 docker”. Your binary depends on an external library, known on Linux as a shared object. Search wikipedia for that term if you want to learn more.

Libc in particular is pretty important but I’ll leave it to others to talk about it. You might find good info also searching “libc”.

1 Like

If you want Rust binaries to work without libc, you have to compile them for the MUSL target.

1 Like

That's probably easier than doing the steps I laid out above. Maybe even more maintainable?

I didn't know about that option. Thanks!

Interesting project. Static linking is one of the things I like about Rust/Cargo. It avoids the OP's issue in the general case.

That error is not because glibc is missing (the rust Docker image has glibc), it's because you compiled the program in an environment with a newer glibc version than the Docker image.

You also don't need to use the rust Docker image at all if you already have your program compiled.


Using a multi-stage Dockerfile you can separate the building/linking-with-musl stage and the "packaging" stage. This way you're left with a small "runner" container that just contains your statically linked, stripped binary. Given the following Dockerfile (in an "example-binary" crate):

FROM ekidd/rust-musl-builder AS builder
ADD . ./
RUN sudo chown -R rust:rust /home/rust/src
RUN cargo build --release
RUN strip /home/rust/src/target/x86_64-unknown-linux-musl/release/example-binary

FROM scratch AS runner
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/example-binary \

ENTRYPOINT [ "/example-binary" ]

...built and tagged an image like so:

$ docker build -t example-binary .
[ output...]
$ docker image ls example-binary
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
example-binary      latest              8ca8ec1b0621        About a minute ago   1.28MB

$ docker run -it example-binary
example-binary 0.1.20

    example-binary [OPTIONS] <SUBCOMMAND>

    -v, --verbose                      Increase logging verbosity
    -h, --help                         Prints help information
    -V, --version                      Prints version information

    help      Prints this message or the help of the given subcommand(s)

I have a more complicated Dockerfile which builds both standalone "runner" containers and RPMs (via cargo-rpm)


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.