0

I am having the same issue as here, but with Docker-Compose. Docker container for Postgres 9.1 not exposing port 5432 to host

Please, note, that I am running Docker on Windows 10.

This is the error that I am still getting pgAdmin at localhost:8080 screenshot

And yes, I've tried using docker inspect with container id and indeed got db IP address and managed to connect to it in PGAdmin, but that IP address changes every time I rerun the container. For example: at one launch it was 172.22.02 and at the next one it was 172.19.0.3 .

When I deploy my whole application I will need to refer to postgresql database by a stable, not-changing IP address, else, I suppose, my application will not start correctly even once.

I have 4 containers in docker-compose: redis, redis-insight, PGAdmin and postgresql. I successfully access these containers:

  • redis via localhost:6379
  • redis_insight via localhost:6380
  • pgadmin via localhost:8080

But I can't access db (which is postgresql db) via localhost:5432 .

It just makes no sense to me, and I've wasted several hours searching for a solution, I have absolutely no idea how to solve this.

Please, help me. Thanks.

This is my docker-compose.yml:

version: '3.8'
services:

  db:
    image: postgres:14.1-alpine3.15
    ports:
      - '5432:5432'
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=1234
      - POSTGRES_DB=telegram_bot_db
    restart: always
    container_name: db
    volumes:
      - db:/var/lib/postgresql/data

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: pgadmin
    restart: always
    depends_on:
      - db
    environment:
      PGADMIN_DEFAULT_EMAIL: some@nicemail.com
      PGADMIN_DEFAULT_PASSWORD: nice
      PGADMIN_LISTEN_PORT: 80
    ports:
      - '8080:80'
    volumes:
      - pgadmin:/var/lib/pgadmin

  redis:
    image: redis
    container_name: redis
    restart: always
    ports:
      - '6379:6379'
    command: redis-server --save 20 1 --loglevel warning --requirepass qwe123qwe
    volumes:
      - redis:/data

  redis_insight:
    image: redislabs/redisinsight:latest
    container_name: redis_insight
    restart: always
    depends_on:
      - redis
    ports:
      - '6380:8001'
    volumes:
      - redis_insight:/db

volumes:
  db:
    driver: local
  redis:
    driver: local
  redis_insight:
    driver: local
  pgadmin:
    driver: local
Tim Kochetkov
  • 149
  • 1
  • 11
  • Also, my liquibase in-app plugin can not access this database either. So I can not even initialize it. – Tim Kochetkov Dec 20 '22 at 15:10
  • `localhost` in Docker almost always means "the current container", so you're trying to tell PGAdmin to connect to itself and not the database. Use the Compose service name `db` instead for connections between containers. (Ignore all of the advice in the linked question about manually looking up the container-private IP addresses, as you already note they don't work reliably.) – David Maze Dec 20 '22 at 15:18
  • And how do I "Use the Compose service name db instead for connections between containers."? I know about host.docker.internal, but it does not help. – Tim Kochetkov Dec 20 '22 at 15:46
  • OK, strangely enough, but it was sufficient to use "db" as a hostname in PGAdmin. Thanks for linking that other question, David. – Tim Kochetkov Dec 20 '22 at 19:19

0 Answers0