-1

i have created 2 containers [pgadmin4 , postgres ] using below docker compose file.

services:
  db:
    container_name: db
    image: postgres
    environment:
      POSTGRES_USER: ashish
      POSTGRES_PASSWORD: ashish
      PGDATA: /data/postgres
      POSTGRESS_DB: jobapp
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: always
  pgadmin:
    container_name: pgadmin4
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: root
    ports:
      - "5050:80"  
    networks:
      - postgres
    restart: always

networks:
  postgres:
      name: postgres
      driver: bridge
      
  1. for both containers, i am using same bridge network namely postgres.
  2. i checked ping status as below to ensure the communication ok.

Ping is successful from pgadmin4 to db

I logged in pgadmin4 over localhost:5050. then i tried creating a server using the credentials passed in compose file.here the address is passed as network name which is 'postgres'

Create Server

with above values, getting error as Name not reloved. then i tried address as 'localhost' and '0.0.0.0' as well but still it failed with error message as connection refused.

NETWORK ID     NAME         DRIVER    SCOPE
1d1c44a0b064   bridge       bridge    local
0e0a1145cf91   host         host      local
06fa74116375   my-network   bridge    local
7e93df1725d9   none         null      local
2a74ae7944da   postgres     bridge    local

above is the response of docker network ls.

cat /data/postgres/pg_hba.conf from db container is resulting into below table.

pg_hba

thanks in advance for your valuable time. any attention is highly appreciated.

4
  • 2
    The name of the postgres server is db, because that's what you chose to call it in your compose file. Commented Apr 2, 2024 at 19:41
  • Does this answer your question? See the answer with docker compose example. Docker - Postgres and pgAdmin 4 : Connection refused Commented Apr 2, 2024 at 19:56
  • hi @larsks just one follow up question, for above compose file , what should be the database properties for spring boot application. i mean i tried as below spring.datasource.url=jdbc:postgresql://db:5432/jobapp spring.datasource.username=ashish spring.datasource.password=ashish but getting error as db cannot be resolved. i tried localhost, ip of my local machine but none of it is working Commented Apr 4, 2024 at 15:33
  • If you sprint boot application is running from the same compose file as postgres and pgadmin, then the database hostname would be db. If the application is running anywhere else, that won't work. If it's running directly on your host, you should be able to use localhost because you are publishing the postgres ports to your host. If that's not working, you may want to open a new question for that specific issue. Commented Apr 4, 2024 at 15:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.