Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A binary built in one image will not start in another because of glibc

Error/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.

  • Applies to Docker Engine 28, Rust stable, Debian bookworm, Alpine 3.2x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 1
  2. 2Match what you see, then jump to its fix

    1. 1Error 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. 2The 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. 3You 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

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' Dockerfile

2Fix

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 app

Confirmed by hub.docker.com

Did this fix it?

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 1

2Fix

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/app

3Verify

Build the image fresh, without a cached copy of the old binary.

docker build --no-cache -t app .

Confirmed by docs.docker.com

Did this fix it?

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' Dockerfile

2Fix

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 app

Confirmed by hub.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.