I am trying to create a server and a db in pgadmin 4. The error message is Unable to connect to server:
connection failed: connection to server at "127.0.0.1", port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections
I created a docker-compose:
version: '3.8'
services: postgres: image: postgres:13 # Version de PostgreSQL container_name: postgres_container environment: POSTGRES_USER: admin POSTGRES_PASSWORD: admin POSTGRES_DB: postgres volumes: postgres_data:/var/lib/postgresql/data - ../src/scripts/data/init.sql:/docker-entrypoint-initdb.d/init.sql # Montez le script
ports: - "5432:5432"
pgadmin: image: dpage/pgadmin4:latest # Image officielle de pgAdmin 4 container_name: pgadmin_container environment: PGADMIN_DEFAULT_EMAIL: admin@admin.com # Email de connexion à pgAdmin PGADMIN_DEFAULT_PASSWORD: admin # Mot de passe pour pgAdmin ports: - "8080:80" # Expose l'interface pgAdmin sur le port 8080 depends_on: postgres volumes: pgadmin_data:/var/lib/pgadmin
volumes: postgres_data: pgadmin_data:
Then I used a init.sql
in the right path and docker-compose up.
This question has found an answer
You should use the servicename postgres
(embedded docker-DNS) instead of the IP 127.0.0.1
(shown in the error-log) for the pgadmin connection.