Getting the issue with psycopg2.connect for Postgres db connectivity, couldnot translate the hostname

Viewed 423

I am using python scripts to create LDAP connection, I have created an empty postgres database in which in want to insert some value, I am not able to connect to the postgres db inside from docker container.

Traceback (most recent call last):
  File "/usr/src/app/ldap_sync_users.py", line 41, in <module>
    connection = psycopg2.connect(user = psqlUser,
  File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "10.120.16.12 " to address: Name or service not known

Dockerfile looks like this
FROM python:3

WORKDIR /usr/src/app

RUN apt-get update && apt-get install -y \
    libsasl2-dev \
    python-dev \
    libldap2-dev \
    libssl-dev \
    python-pip

RUN pip install python-ldap
RUN pip install psycopg2

COPY ldap_file.py ./

CMD python ldap_sync_users.py 

and i use another docker script file 

#!/bin/bash

docker run -i \
    --name ldap_sync \
    --env-file=environment \
    --add-host=database:10.120.16.12 \
       ldapsync
0 Answers
Related