0

Good afternoon everyone. I started learning docker and I have a question. There is a simple python docker image with the psycopg2 library. I want to connect to a database on a server accessed via openvpn. as a result, there is a piece of python code and ovpn. what needs to be done for docker to see the host?

Thanks in advance for taking the time to answer such a stupid question.

I ran a simple docker image and when the script tries to connect, the error "psycopg2.OperationalError: could not translate host name "name_host" to address: Name or service not known" occurs

  • What is your setup? Do you have the VPN installed on your host machine? Or do you want to setup VPN inside the docker container? The error you posted looks like you are forgetting to set some environment variable or similar somewhere. – Garuno Jan 23 '23 at 10:05
  • @Garuno, I have an openvpn config file .ovpn so that I can connect to a server that has a database. On my own computer, I run OpenVPN and connect easily, but I want to be able to do this in docker. Sorry if I didn't describe the problem well. – Tironii Jan 23 '23 at 10:18
  • Does [this](https://stackoverflow.com/questions/68062426/openvpn-inside-docker-image) answer your question? – Garuno Jan 23 '23 at 10:24
  • Yes, before writing a question, I read this link, but I could not use it for myself. I have a simple dockerfile code: FROM python WORKDIR /app RUN pip install psycopg2 COPY . . CMD [ "python", "main.py" ] I kind of realized that I need to additionally specify a link to the .ovpn file with the given log/pass, but it didn’t work out – Tironii Jan 23 '23 at 10:36
  • Okay what is the error? If you want to use openvpn in your container you need to add it in your Dockerfile like in the linked question. – Garuno Jan 23 '23 at 10:45
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 23 '23 at 12:27
  • I solved the problem by raising ubuntu with openvpn and through the docker compose the network sees everything. The only problem is that DNS does not sync and does not work by hostname – Tironii Jan 23 '23 at 13:09

0 Answers0