You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署thajeztah/pgadmin4连接本地PostgreSQL的IP地址问题

Connecting pgAdmin4 (Docker) to Local PostgreSQL on Linux Mint

Hi Thomas, great question! When you run pgAdmin4 inside a Docker container, using localhost won’t work—each container has its own isolated network stack, so localhost inside the container points to the container itself, not your Linux Mint host machine. Here’s how to fix this:

Reliable Connection Methods

1. Use Your Host’s Private IP Address

This is the most straightforward and consistent approach:

  • Open your Linux Mint terminal and run this command to get your private IP (the one your machine uses on your local network):
    ip addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v 127.0.0.1
    
    You’ll get an output like 192.168.1.42—enter this IP in the Host name/address field when adding your new server in pgAdmin4.

2. Use Docker’s Host Gateway IP (Linux-Specific)

Docker’s default bridge network has a gateway that points to your host machine. By default, this is usually 172.17.0.1, but you can confirm it with:

  • First, get your pgAdmin4 container ID:
    docker ps
    
  • Then check the gateway IP:
    docker inspect <your-container-id> | grep Gateway
    
    Use the resulting IP (e.g., 172.17.0.1) as the host address in pgAdmin4.

Critical Pre-Checks

Before connecting, make sure PostgreSQL is configured to accept external connections:

  1. Update pg_hba.conf (usually located at /etc/postgresql/9.6/main/pg_hba.conf):
    Add a line to allow connections from your Docker network or private IP range. For example:
    # Allow connections from Docker's default bridge network
    host    all             all             172.17.0.0/16         md5
    # Or allow connections from your local network
    host    all             all             192.168.1.0/24         md5
    
  2. Update postgresql.conf:
    Set listen_addresses to * so PostgreSQL listens on all network interfaces:
    listen_addresses = '*'
    
  3. Restart PostgreSQL to apply changes:
    sudo systemctl restart postgresql
    

Either of the connection methods above should work for your setup. I’d recommend using your private IP since it’s more stable if your Docker network configuration changes.

内容的提问来源于stack exchange,提问作者ThomasDKim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:39:44