when I build the rust app using the alpine as the base image using this command:
docker build -f ./Dockerfile -t="reddwarf-pro/reddwarf-admin:v.1.0.0" .
show error like this:
#14 222.9 = note: /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lpq
#14 222.9 collect2: error: ld returned 1 exit status
#14 222.9
#14 222.9
#14 223.0 warning: `reddwarf-admin` (bin "reddwarf-admin") generated 1 warning
#14 223.0 error: could not compile `reddwarf-admin` due to previous error; 1 warning emitted
------
executor failed running [/bin/sh -c cargo build --release]: exit code: 101
I have already add the libpq
in the alpine image, why still show this error? what should I do to fix this problem? This is the Dockerfile:
# to reduce the docker image size
# build stage
FROM rust:1.54-alpine as builder
WORKDIR /app
COPY . /app
RUN rustup default stable
RUN apk update && apk add --no-cache libpq musl-dev pkgconfig openssl-dev gcc
RUN cargo build --release
# RUN cargo build
# Prod stage
FROM alpine:3.15
WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
# ENV ROCKET_PORT=11014
RUN apk update && apk add --no-cache libpq curl
COPY --from=builder /app/.env /app
COPY --from=builder /app/settings.toml /app
COPY --from=builder /app/target/release/reddwarf-admin /app/
COPY --from=builder /app/Rocket.toml /app
CMD ["./reddwarf-admin"]
I am also tried to add libpq-dev
but it seems the alpine did not contains this library.
2
Answers
The dependency you need is:
libpq-dev
Perhaps slightly confusingly, the dev version is called
postgresql-dev
and notlibpq-dev
in v3.14. (From what I can tell, it was renamedlibpq-dev
in v3.15).libpq
does indeed install the shared library, butpostgresql-dev
creates the symbolic link/usr/lib/libpq.so -> libpq.so.5.13
which makes linking succeed.From
man ld
:That is, the
-lname
syntax will only search forlibname.(a|so)
, not versioned names.