A binary built in one image will not start in another because of glibc
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./app)Short answer
The binary was linked against a newer glibc than the image it now runs in. Compare the base image of the build stage with the base image of the final stage. Use the same Debian or Ubuntu release for both, or build with an Alpine (musl) toolchain so no glibc version is needed.
Fix it fast
1Find out which cause you have
Print the glibc version each image ships, once for the stage that builds and once for the stage that runs. The final stage must be the same or newer.
docker run --rm rust:1 ldd --version | head -n 1 docker run --rm debian:bullseye-slim ldd --version | head -n 12Match what you see, then jump to its fix
- 1
Error names GLIBC_2.3x and the final stage uses an older base such as bullseye or Ubuntu 20.04The final image is an older release than the build imageFix - 2
The binary works on your laptop or build server but fails as soon as it is copied into the imageCompiled on the host or in CI, then copied into a containerFix - 3
You ship to several base images, or to a minimal image such as Alpine or scratchYou want one binary that does not depend on the image's glibcFix
- 1
What does the error look like?
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./app)
Cause 1 of 3
The final image is an older release than the build image
1Check
Look at the two FROM lines. The rust image is built on a current Debian release, so a binary compiled there can ask for a glibc version that an older runtime image does not have.
grep -n '^FROM' Dockerfile2Fix
Pin both stages to the same Debian release, for example bookworm for the build and bookworm-slim for the run stage. Docker's Rust image page documents the -bookworm tag and the pattern of compiling in the full image and copying the binary into a slimmer runtime image.
FROM rust:1-bookworm AS build
WORKDIR /src
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=build /src/target/release/app /usr/local/bin/app
CMD ["app"]3Verify
Rebuild and run the image. The loader error is gone and the app starts.
docker build -t app .
docker run --rm appConfirmed by hub.docker.com
Cause 2 of 3
Compiled on the host or in CI, then copied into a container
1Check
A binary built outside Docker is linked against the glibc of that machine. Compare it with the image that runs it.
ldd --version | head -n 1
docker run --rm debian:bookworm-slim ldd --version | head -n 12Fix
Build inside the Dockerfile with a multi-stage build, so the compiler and the final image are chosen together. Only the artefacts you copy with COPY --from reach the final image.
FROM rust:1-bookworm AS builder
WORKDIR /src
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /src/target/release/app /usr/local/bin/app3Verify
Build the image fresh, without a cached copy of the old binary.
docker build --no-cache -t app .Confirmed by docs.docker.com
Cause 3 of 3
You want one binary that does not depend on the image's glibc
1Check
Rust's musl targets are listed in the platform support table. The rust:alpine image uses musl instead of glibc, so a binary built there never asks for a glibc symbol version.
grep -n '^FROM' Dockerfile2Fix
Build in the Alpine variant of the Rust image and run on Alpine. Some native libraries may need extra packages because Alpine does not ship tools such as bash or git by default.
FROM rust:alpine AS build
WORKDIR /src
COPY . .
RUN cargo build --release
FROM alpine:latest
COPY --from=build /src/target/release/app /usr/local/bin/app
CMD ["app"]3Verify
Run the image. A musl build starts on Alpine without any glibc message.
docker build -t app . && docker run --rm appConfirmed by hub.docker.com
How do I stop it coming back?
- Pin the Debian or Ubuntu release in both FROM lines instead of using latest.
- Build inside the Dockerfile, not on the host, so the toolchain and runtime image are chosen together.
- When you upgrade the build image, upgrade the run image in the same commit.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A container starts and stops at once with exec format error
exec /usr/bin/sh: exec format error
The kernel was asked to run a file it cannot execute.
4 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix