I am using docker to build a diesel rust application, For ease of deployment i am using the below DockerFile to create the image, but when i try to run it , it gives the error
/app/rest-jwt-rust: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
i have tried installing libqp5 and libpqdev with my installation, but still having the same problem.
#build from latst rust version
FROM rust:latest as build
# install libpq, libsqlite and create new empty binary project
RUN apt-get update; \
apt-get install -y --no-install-recommends postgresql-common libpq-dev libpq5 libpq-dev libsqlite3-dev; \
USER=root cargo new --bin app
WORKDIR /app
# copy manifests
COPY ./Cargo.toml ./Cargo.toml
# build this project to cache dependencies
RUN cargo build; \
rm src/*.rs
# copy project source and necessary files
COPY ./src ./src
COPY ./migrations ./migrations
COPY ./diesel.toml .
COPY ./.env .
# rebuild app with project source
RUN rm ./target/debug/deps/rest_jwt_rust*; \
cargo build --release
# deploy stage
FROM debian:buster-slim
# create app directory
RUN mkdir app
WORKDIR /app
# install libpq and libsqlite
RUN apt-get update; \
apt-get install -y --no-install-recommends postgresql-common libpq-dev libpq5 libpq-dev libsqlite3-dev; \
rm -rf /var/lib/apt/lists/*
# copy binary and configuration files
COPY --from=build /app/target/release/rest-jwt-rust .
COPY --from=build /app/.env .
COPY --from=build /app/diesel.toml .
COPY ./wait-for-it.sh .
# expose port
EXPOSE 8080
# run the binary
CMD ["/app/rest-jwt-rust"]
using libpq-dev during build and libpq5 for deploy and upgrading to bookworm made it work.