Error loading shared library libpq.so.5: No such file or directory (docker + diesel)

I'm trying to build an application that is using diesel as the ORM library.
The application will be build as a docker image.
When building the image I am installing postgres:

RUN apt-get install postgresql -y

I also tried adding libpq in hope to resolve the linking issues.
Still, when running my container I'm getting:

Error loading shared library libpq.so.5: No such file or directory (needed by /usr/local/bin/rustbinary)
Error relocating /usr/local/bin/rustbinary: PQresultStatus: symbol not found
Error relocating /usr/local/bin/rustbinary: PQresultErrorMessage: symbol not found
Error relocating /usr/local/bin/rustbinary: PQprepare: symbol not found
Error relocating /usr/local/bin/rustbinary: PQnfields: symbol not found
Error relocating /usr/local/bin/rustbinary: PQgetvalue: symbol not found
Error relocating /usr/local/bin/rustbinary: PQcmdTuples: symbol not found
Error relocating /usr/local/bin/rustbinary: PQclear: symbol not found
Error relocating /usr/local/bin/rustbinary: PQgetlength: symbol not found
Error relocating /usr/local/bin/rustbinary: PQconnectdb: symbol not found
Error relocating /usr/local/bin/rustbinary: PQexecPrepared: symbol not found
Error relocating /usr/local/bin/rustbinary: PQfinish: symbol not found
Error relocating /usr/local/bin/rustbinary: PQerrorMessage: symbol not found
Error relocating /usr/local/bin/rustbinary: PQftype: symbol not found
Error relocating /usr/local/bin/rustbinary: PQstatus: symbol not found
Error relocating /usr/local/bin/rustbinary: PQsetNoticeProcessor: symbol not found
Error relocating /usr/local/bin/rustbinary: PQntuples: symbol not found
Error relocating /usr/local/bin/rustbinary: PQfname: symbol not found
Error relocating /usr/local/bin/rustbinary: PQresultErrorField: symbol not found
Error relocating /usr/local/bin/rustbinary: PQgetisnull: symbol not found
Error relocating /usr/local/bin/rustbinary: PQexec: symbol not found

I also tried installing

RUN apt-get install libpq-dev

which didn't resolve the problem as well.

Can anybody help me to find a solution?

I still didn't manage to solve this.
Does somebody have an idea?

what is your ubuntu and postgresl version ?

1 Like

My image is based on docker-rust which itself is based on alpine.

I'm simply installing a fresh version of postgresql via apt inside the image.

psql --version

returns:

psql (PostgreSQL) 11.7 (Debian 11.7-0+deb10u1)

Alpine has apk, not apt afaik.

1 Like

Oh wait, the default docker-rust image isn't based on alpine.
I assumed it would, but the alpine one is just a variant:

rust:<version>-alpine
This image is based on the popular Alpine Linux project available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

I'm not using this one though.
So apparently the version I'm using is based on Debian.
Thanks for pointing that out. Makes a lot more sense too.

So do you resolve your problem or you still need help ?

1 Like

I just solved it by basically switching to the alpine image and installing postgres in there.
I don't know why it did the trick and why it didn't work with Debian, but I'm happy that it works now.

Glad it works for you. Although the problem is not clear enough for future users.

Yes, I'm afraid it isn't.
Thanks for your help though.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.