0

I am trying to build a docker image of a flask app that works on my laptop. This app is used to generate PostgreSQL dumps with Python. So I need to add pg_dump and libpq.so.5. See below my Dockerfile :

FROM XXX/postgres:13.9-alpine as postgres
FROM XXX/python:3.8-alpine

USER root

WORKDIR /dump_generator_api

COPY requirements.txt ./
RUN python3 -m pip install --upgrade pip
RUN pip3 install -r requirements.txt

COPY --from=postgres /usr/local/bin/pg_dump /usr/local/bin/pg_dump
COPY --from=postgres /usr/local/lib/libpq.so.5 /usr/local/lib/libpq.so.5

ADD . /dump_generator_api
EXPOSE 5000
CMD ["python", "/dump_generator_api/app.py"]

Once I have build my image, I try to apply a pg_dump command (/usr/local/bin # pg_dump -U pgsqladmin -h XXX -p XXX XXX> backup.sql) and I have the following error I don't understand :

Error loading shared library libldap.so.2: No such file or directory (needed by /usr/local/lib/libpq.so.5)
Error relocating /usr/local/lib/libpq.so.5: ldap_err2string: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_result: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_simple_bind: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_count_entries: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_unbind: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_set_option: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_search_st: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_value_free_len: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_get_values_len: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_first_entry: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_init: symbol not found
Error relocating /usr/local/lib/libpq.so.5: ldap_msgfree: symbol not found

Do you know how I can solve it ? I tried different docker images and same errors occur. I don't know where and how I should add this libldap.so.2.

lbened
  • 65
  • 6

1 Answers1

2

Copying pg_dump and libpq.so.5 from the postgres image will not work, each binary depends on other packages.

You should just install postgres on your image using "apk add postgresql" it would be installed along with everything that it needs.

The file would look like:

FROM XXX/python:3.8-alpine

USER root

WORKDIR /dump_generator_api

COPY requirements.txt ./
RUN python3 -m pip install --upgrade pip
RUN pip3 install -r requirements.txt

RUN apk update && apk add postgresql

ADD . /dump_generator_api
EXPOSE 5000
CMD ["python", "/dump_generator_api/app.py"]
akathimi
  • 1,393
  • 11
  • When I do pg_dump command now I have : pg_dump: [archiver (db)] connection to database "dbtest" failed: SCRAM authentication requires libpq version 10 or above – lbened Feb 07 '23 at 12:23
  • 1
    libpq should be installed with postgresql, what is weird is that im using the python:alpine3.8 to test, and when running `apk add postgresql` libpq v10.12-r0 is being installed. Please check which version of libpq is being installed. Also, check this answer https://stackoverflow.com/questions/62807717/how-can-i-solve-postgresql-scram-authentication-problem – akathimi Feb 07 '23 at 12:40
  • 1
    Thank you @akathimi it works now like you said above ! – lbened Feb 07 '23 at 14:08