我认为 rust 编译器使用静态绑定并在编译时包含所有依赖库(因此可执行文件大小)。
但是,当我尝试在带有 actix、mysql 客户端和启用了 mysql 功能的柴油机中使用已编译的二进制文件时,会弹出此错误:
error while loading shared libraries: libmariadb.so.3: cannot open shared object file: No such file or director
我的码头文件:
FROM rust:1.43 as builder
WORKDIR /var/app
RUN apt-get update && apt-get install -y libclang-dev clang libmariadb-dev-compat libmariadb-dev
COPY Cargo.toml Cargo.lock diesel.toml ./
COPY src src
RUN cargo install diesel_cli --no-default-features --features mysql
RUN cp /usr/local/cargo/bin/diesel diesel
RUN cargo build --release
FROM ubuntu
USER 1000
WORKDIR /var/app
COPY --from=builder --chown=1000:1000 /var/app/target/release/sniper_api app
COPY --from=builder --chown=1000:1000 /var/app/diesel diesel
CMD ["./app"]
我的货物:
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"
actix-http = "1.0.1"
serde = { version = "1.0.112", features=["derive"] }
dotenv = "0.15.0"
config = "0.10.1"
diesel = { version = "1.4.2", features = ["mysql","r2d2"]}
futures = "0.3.5"
r2d2 = "0.8.8"
r2d2_mysql = "18.0.0"
env_logger = "0.7.1"
但是如果我使用 ubuntu/debian/etc。图像作为运行时并安装libmariadb-dev-compat libmariadb-dev
一切都很好。有没有办法在 Rust 中使用 mysql 连接器获得真正的单一二进制文件?