I am trying to connect my local postgres database using pgAdmin4 docker container. When I open http://localhost:5050/
and login after create new server connection I got Unable to connect to server: could not connect to server: Connection refused
error message.
Here is my docker-compose.yml
file
version: '3.5'
services:
pgadmin:
container_name: pgadmin4
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: odoo
volumes:
- pgadmin:/root/.pgadmin
ports:
- "5050:80"
restart: unless-stopped
volumes:
pgadmin:
I am finding solution to connect my local postgres databasw with pgadmin4 docker container. I am using Ubuntu 20.04 os system.
---- Updated base on @Veikko answer -----------
Here is my docker-compose file code https://pastebin.com/VmhZwtaL
and here is postgresql.conf file https://pastebin.com/R7ifFrGR
and pg_hba.conf file https://pastebin.com/yC2zCfBG
If pgAdmin displays this message, there are two possible reasons for this: the database server isn't running - simply start it. the server isn't configured to accept TCP/IP requests on the address shown.
You can use image qoomon/docker-host
to access services on your host computer. Add docker-host service to your docker-compose like this:
version: '3.5'
services:
docker-host:
image: qoomon/docker-host
cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
restart: on-failure
pgadmin:
container_name: pgadmin4
image: dpage/pgadmin4
environment:
...
After this you should be able to access your host Postgres service with host name docker-host. Replace localhost
with docker-host
in your connection string and connection should work.
If problems with connection after this, please make sure you do not have any firewall blocking the traffic, you have proper Docker network setup (see docs) and your postgresql is listening to this address.
Ubuntu/linux version of Docker does not currently support host.docker.internal DNS name that would point containers to the host. That is the easiest way to link to host in Docker for Mac or Windows. I hope we get this also to Linux soon.
More information about docker-host can be found in Github repo: https://github.com/qoomon/docker-host
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With