# Docker and postgres: Error: connect ETIMEDOUT

**URL:** <https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831>\
**Category:** General\
**Created:** [March 19, 2020, 3:51am UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831 "2020-03-19T03:51:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostspirit96](https://avatars.discourse-cdn.com/v4/letter/l/e495f1/32.png) [@lostspirit96](https://forums.docker.com/u/lostspirit96)\
**Post date:** [March 19, 2020, 3:51am UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/1 "2020-03-19T03:51:38Z")

</div>

Hello I have a problem with my docker compose postgres and pgadmin

Error:

```
Error: connect ETIMEDOUT 172.19.0.2:5432 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16) { errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'connect',
address: '172.19.0.2', port: 5432 }

```

my docker compose:

```auto
version: "3.7"
services:
  postgres:
    image: postgres:12
    restart: always
    container_name: "postgres_container"
    ports:
      - "5432:5432"
    volumes:
      - db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: spirit
      POSTGRES_PASSWORD: emasa
      POSTGRES_DB: emasa
  pgadmin:
    image: dpage/pgadmin4
    container_name: "pgadmin_container"
    depends_on:
      - postgres
    ports:
      - 5050:80
    environment:
      PGADMIN_DEFAULT_EMAIL: emasa@emasa.com
      PGADMIN_DEFAULT_PASSWORD: admin
volumes:
  db_data:

```

i’m not able to imagine the reason for my error i give a docker-compose log and my postgres works normal:

```auto
postgres_container | 2020-03-19 02:48:12.162 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_container | 2020-03-19 02:48:12.162 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_container | 2020-03-19 02:48:12.184 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_container | 2020-03-19 02:48:12.256 UTC [24] LOG: database system was shut down at 2020-03-19 02:48:04 UTC
postgres_container | 2020-03-19 02:48:12.290 UTC [1] LOG: database system is ready to accept connections

```

I think the problem is this: listening on IPv4 address “0.0.0.0”, port 5432

and this is my config:

```auto
{
  "type": "postgres",
  "host": "172.19.0.2",
  "port": 5432,
  "username": "spirit",
  "password": "emasa",
  "database": "emasa",
  "synchronize": true,
  "logging": false,
  "entities": ["src/entity/**/*.ts"],
  "migrations": ["src/migration/**/*.ts"],
  "subscribers": ["src/subscriber/**/*.ts"],
  "cli": {
    "entitiesDir": "src/entity",
    "migrationsDir": "src/migration",
    "subscribersDir": "src/subscriber"
  }
}

```

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 19, 2020, 6:12am UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/2 "2020-03-19T06:12:19Z")

</div>

> [@lostspirit96](#):
>
> “host”: “172.19.0.2”,

Whatever you do, never ever use a container’s ip to connect to its containerized service. usualy people trying to access a container by it’s ip, do something not indendet to be done like this. A container can and will change its ip when re-created.

Please replace the container’s ip with its servicename and try again.

---

<div class="post-metadata">

**Author:** ![lostspirit96](https://avatars.discourse-cdn.com/v4/letter/l/e495f1/32.png) [@lostspirit96](https://forums.docker.com/u/lostspirit96)\
**Post date:** [March 19, 2020, 6:48am UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/3 "2020-03-19T06:48:55Z")

</div>

I tried with the name of the container and had this new error:

Error: getaddrinfo ENOTFOUND postgres\_container  
at GetAddrInfoReqWrap.onlookup

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 19, 2020, 6:50am UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/4 "2020-03-19T06:50:23Z")

</div>

Please share your exact configuration, why would the error message say “postgres\_container”?! Did you change the service name from postgres to postgres\_container? the service name is NOT the container name.

---

<div class="post-metadata">

**Author:** ![lostspirit96](https://avatars.discourse-cdn.com/v4/letter/l/e495f1/32.png) [@lostspirit96](https://forums.docker.com/u/lostspirit96)\
**Post date:** [March 19, 2020, 6:54am UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/5 "2020-03-19T06:54:33Z")

</div>

yes my docker-compose:

```
version: "3.7"

services:

  postgres:

    image: postgres:12

    restart: always

    container_name: "postgres_container"

    ports:

      - "5432:5432"

    volumes:

      - db_data:/var/lib/postgresql/data

    environment:

      POSTGRES_USER: spirit

      POSTGRES_PASSWORD: emasa

      POSTGRES_DB: emasa

  pgadmin:

    image: dpage/pgadmin4

    container_name: "pgadmin_container"

    depends_on:

      - postgres

    ports:

      - 5050:80

    environment:

      PGADMIN_DEFAULT_EMAIL: emasa@emasa.com

      PGADMIN_DEFAULT_PASSWORD: admin

volumes:

  db_data:

```

and my config:

```
{

  "type": "postgres",

  "host": "postgres_container",

  "port": 5432,

  "username": "spirit",

  "password": "emasa",

  "database": "emasa",

  "synchronize": true,

  "logging": false,

  "entities": ["src/entity/**/*.ts"],

  "migrations": ["src/migration/**/*.ts"],

  "subscribers": ["src/subscriber/**/*.ts"],

  "cli": {

    "entitiesDir": "src/entity",

    "migrationsDir": "src/migration",

    "subscribersDir": "src/subscriber"

  }

}

```

my postgres contianer has this name

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [March 19, 2020, 6:04pm UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/6 "2020-03-19T18:04:06Z")

</div>

> [@meyay](#):
>
> the service name is NOT the container name.

The service name of your postgres service is `postgres`, NOT postgres\_container.

---

<div class="post-metadata">

**Author:** ![jeffersonsousa](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jeffersonsousa/32/28763_2.png) [@jeffersonsousa](https://forums.docker.com/u/jeffersonsousa)\
**Post date:** [November 9, 2020, 8:16pm UTC](https://forums.docker.com/t/docker-and-postgres-error-connect-etimedout/90831/7 "2020-11-09T20:16:49Z")

</div>

Someone managed to solve? Help me.
