2

Consider the Docker-compose :

version: "3"
services:
  postgres_svc:
    image: postgres:12.0-alpine
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: myCoolPassword
      POSTGRES_DB: postgres      
    ports:
      - "5432:5432"


   ... More services

When I run Docker-compose up and run :

docker inspect <POSTGRES_ID> | grep Gateway >>> 192.168.16.1

or

docker inspect <POSTGRES_ID>| grep IPAddress  >>> 192.168.16.3

I get the IP/Gateway of the postgres container , and then in PGADMIN :

enter image description here

enter image description here

And the same thing for the IP 192.168.16.3.

How can we solve this connection problem ?

JAN
  • 21,236
  • 66
  • 181
  • 318
  • 1
    Ignore the `docker inspect` IP addresses, which don't work in many common scenarios. Use `localhost` (usually) as the host name, and the first `ports:` number. – David Maze Jan 10 '21 at 14:42
  • 2
    (Or if pgadmin is in the same Compose file, the service name `postgres_svc` and the standard PostgreSQL port 5432, ignoring `ports:`.) – David Maze Jan 10 '21 at 14:43
  • @DavidMaze: You're a goddamn genius ,I've added a `pgadmin` service and it worked fine with calling `postgres_svc` as the host. Please post your answer officially and I'll accept it! – JAN Jan 10 '21 at 16:37
  • 1
    Both variants on this are described in the linked question (along with several `docker inspect`-based options). – David Maze Jan 10 '21 at 17:27
  • @DavidMaze: It's close but not really , the trick was to add a new Service to Docker-compose : a `pgAdmin` service , and then and only then , the host `postgres_svc` would be identified by its name , without using any IP/Gateway of any other lie.Thanks a lot! – JAN Jan 11 '21 at 07:41

0 Answers0