J
J
jenya77712021-08-06 17:25:44
PostgreSQL
jenya7771, 2021-08-06 17:25:44

Why is accessing the local database from Docker not working?

I set everything up according to the answers from this article .
Here's what happened:

version: "3.7"

services:
  redis:
    container_name: redis
    image: redis:6.2
    restart: always
    volumes:
      - /data
    ports:
      - 6379:6379

  app:
    container_name: app
    restart: always
    image: bot:staging
    env_file: .env
    environment:
      - DB_HOST=host.docker.internal
      - REDIS_HOST=redis
    ports:
      - 3000:3000
    extra_hosts:
      host.docker.internal: host-gateway
    external_links:
      - redis
    depends_on:
      - redis


Also set up PG.

I test that PG works as it should:
pg_isready -h 172.17.0.1 -p 5432 -U bot  -d bot
res -> 172.17.0.1:5432 - accepting connections


And when I try to connect in docker, I get this error:
Error: connect ETIMEDOUT 172.17.0.1:5432                                   
   at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1142:16) {    
   errno: -110,                                                             
   code: 'ETIMEDOUT',                                                       
   syscall: 'connect',                                                      
   address: '172.17.0.1',                                                   
   port: 5432                                                               
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Goldobin, 2021-08-08
@Geminix

If you enter the shell of the container with the application, will the database server be pinged?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question