/lib/x86_64-linux-gnu/libc.so.6:找不到版本“GLIBC_2.33”

问题描述 投票:0回答:1

我在运行容器时遇到问题。在我的项目中有 3 个不同的容器(一个用于后端,一个用于前端,一个用于 mongodb),最后两个工作正常,但第一个(用于后端的)给了我以下错误:

backend-1   | backend: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by backend)
backend-1   | backend: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by backend)
backend-1   | backend: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by backend)

并退出,状态码:1 这是 dockerfile

# Stage 1: Build the Rust app
FROM rust:1.76 as builder

WORKDIR /app

# Cache dependencies
COPY Cargo.toml Cargo.lock ./
RUN mkdir src
RUN echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -rf src

# Copy source code and build the project
COPY . ./
RUN cargo build --release

# Stage 2: Create a lightweight image for the Rust app
FROM debian:buster-slim

RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl1.1 ca-certificates && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/target/release/backend /usr/local/bin/backend

EXPOSE 8080

CMD ["backend"]

这是 docker-compose 文件

version: '3.8'

services:
  frontend:
    build:
      context: ./frontend
    ports:
      - "3000:80"
    depends_on:
      - backend

  backend:
    build:
      context: ./backend
    ports:
      - "8080:8080"
    environment:
      MONGO_URL: "mongodb://mongo:27017/wellness-tracker"
    depends_on:
      - mongo

  mongo:
    image: mongo:5.0
    volumes:
      - mongo-data:/data/db
    ports:
      - "27017:27017"

volumes:
  mongo-data:

我尝试过更改几个发行版,例如

Ubuntu (20.04/21.*/22.04)
rust:1.76-slim-buster -> both on the first and second stage (cause someone suggested that I have a glibc mismatch, because build for glibc Version A, but deploy the binary to Version C)

并使用简化的 dockerfile 但仍然没有。 我已经尝试了问题中建议的解决方案,但出现了相同的错误,但对我来说仍然没有任何作用......

docker rust docker-compose dockerfile
1个回答
0
投票

“buster”debian 版本相当旧,并且提供了相当旧的 (2.28) glibc,这解释了为什么你会缺少更现代的 glib 符号:

$ docker run -it debian:buster-slim /usr/bin/ldd --version  
ldd (Debian GLIBC 2.28-10+deb10u3) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

您可以使用较新版本的 debian 来获取它们,例如“sid”:

$ docker run -it debian:sid-slim /usr/bin/ldd --version
ldd (Debian GLIBC 2.38-13) 2.38
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

要使用它,只需替换第二个

FROM
指令中的图像名称:

# Stage 2: Create a lightweight image for the Rust app
FROM debian:sid-slim
© www.soinside.com 2019 - 2024. All rights reserved.