【问题标题】:Docker container exit with error code error libcurl not foundDocker 容器退出,错误代码为 error libcurl not found
【发布时间】:2022-12-04 07:25:59
【问题描述】:

我正在构建一个容器,你可以看到 docker 文件,它用于在 Argonaut 上部署 Rust 应用程序。但无法启动。在这里你可以看到 Dockerfile。

FROM rust:1.64.0-buster AS builder
WORKDIR /app

ARG TOKEN
ARG DATABASE_URL

RUN git config --global url."https://${TOKEN}:@github.com/".insteadOf "https://github.com/"

COPY . .

ENV CARGO_NET_GIT_FETCH_WITH_CLI true

RUN rustup component add rustfmt
RUN apt-get update -y && apt-get install git wget ca-certificates curl gnupg lsb-release cmake libcurl4 -y

RUN cargo build

FROM debian:buster-slim
WORKDIR /app
COPY --from=builder /app/target/debug/linkedin /app/target/release/linkedin
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

CMD ["/app/target/release/linkedin"]
EXPOSE 3000

它构建成功,但当它工作时,它会以错误代码 127 退出。

linkedin-leadr-1  | /app/target/release/linkedin: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

没有发现它有什么问题,即使我正在安装 libcurl4。但是我的 docker 容器找不到它。你能给我解决方案吗?

【问题讨论】:

    标签: docker rust


    【解决方案1】:

    看起来您的 Dockerfile 缺少将 libcurl 共享库复制到容器中的步骤。这就是当您尝试运行容器时收到“加载共享库时出错”消息的原因。

    要解决此问题,您可以向 Dockerfile 添加一个步骤,将 libcurl 共享库从构建器阶段复制到最终容器中。这是您如何执行此操作的示例:

    FROM rust:1.64.0-buster AS builder
    WORKDIR /app
    
    ARG TOKEN
    ARG DATABASE_URL
    
    RUN git config --global url."https://${TOKEN}:@github.com/".insteadOf "https://github.com/"
    
    COPY . .
    
    ENV CARGO_NET_GIT_FETCH_WITH_CLI true
    
    RUN rustup component add rustfmt
    RUN apt-get update -y && apt-get install git wget ca-certificates curl gnupg lsb-release cmake libcurl4 -y
    
    RUN cargo build
    
    # Copy the libcurl shared library from the builder stage into the final container
    RUN mkdir -p /usr/local/lib && 
        cp /usr/lib/x86_64-linux-gnu/libcurl.so.4 /usr/local/lib && 
        ln -s /usr/local/lib/libcurl.so.4 /usr/local/lib/libcurl.so
    
    FROM debian:buster-slim
    WORKDIR /app
    COPY --from=builder /app/target/debug/linkedin /app/target/release/linkedin
    COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
    
    CMD ["/app/target/release/linkedin"]
    EXPOSE 3000
    

    您需要根据您的系统和您使用的 libcurl 版本调整 libcurl 共享库的路径。上面的示例假设您在 64 位 Linux 系统上运行并使用 libcurl 版本 4。

    进行此更改并重建容器后,您应该能够运行它而不会遇到“加载共享库时出错”消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 2019-04-07
      • 2020-09-22
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多