Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
¿Cómo compartir la base de datos local de Postgres con Docker?

Tengo un proyecto django con base de datos PostgreS. Necesito usar mi base de datos local en el contenedor docker. ¿Cómo compartir el host local de la máquina con el contenedor docker? Mi docker-compose.yml :

 version: '3' services: web: build: ./ network_mode: "host" command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput --i rest_framework && gunicorn orion-amr.wsgi:application --bind 0.0.0.0:8000 --workers=2" ports: - "${webport}:8000" - "${pgport}:${pgport}" env_file: - ./.env

Configuración de Django.py:

 DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': os.environ.get('pgdatabase'), 'USER': os.environ.get('pguser'), 'PASSWORD': os.environ.get('pgpassword'), 'HOST': os.environ.get('pghostname'), 'PORT': os.environ.get('pgport'), } }

yo añadí

 listen_addresses = '*'

al archivo postgresql.conf y debajo está mi archivo pg_hba.conf :

 # TYPE DATABASE USER ADDRESS METHOD # IPv4 local connections: host all all 0.0.0.0/0 trust # IPv6 local connections: host all all ::/0 trust # Allow replication connections from localhost, by a user with the # replication privilege. host replication all 127.0.0.1/32 trust host replication all ::1/128 trust

Ahora tengo un error:

 web_1 | django.db.utils.OperationalError: could not connect to server: Connection refused web_1 | Is the server running on host "127.0.0.1" and accepting web_1 | TCP/IP connections on port 5432? web_1 |

¿Quién puede ayudarme? ¡Por favor!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

parece que os.environ.get('pghostname') apunta a 127.0.0.1 donde 127.0.0.1 significa este contenedor, no Host DB. como el error

 Is the server running on host "127.0.0.1" and accepting

Para conectarse con la base de datos del host, tiene un DNS especial para mac y window host.docker.internal . El host de base de datos debe ser

 'HOST': "host.docker.internal"

Para conectarse con HOST DB, o si está en Linux, entonces debería ser

 'HOST': "HOST_IP"

Puede obtener la IP del host desde ifconfig .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!