我正在尝试连接一个独立容器中的Postgres数据库,该容器与存储Go服务器的另一个单独容器不同:

Pool, err = pgxpool.Connect(context.Background(),"postgres://postgres:postgres@postgres:5432/postgres")

这样做之后,我收到以下错误:

2020/09/25 13:40:08 failed to connect to `host=postgres user=postgres database=postgres`: hostname resolving error (lookup postgres on 192.168.65.1:53: no such host)
docker-compose.yml
version: "3.8"
services:
  postgres:
    image: postgres:alpine
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - 5432:5432
    restart: always
  server:
    build: .
    depends_on:
      - postgres
    ports:
      - "2302:2302"
      - "80:80"
    restart: always

我能够成功地从我的操作系统连接到Postgres数据库。Postgres容器初始化日志如下:

postgres_1  | 
postgres_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1  | 
postgres_1  | 2020-09-25 15:37:50.529 UTC [1] LOG:  starting PostgreSQL 13.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
postgres_1  | 2020-09-25 15:37:50.529 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2020-09-25 15:37:50.529 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2020-09-25 15:37:50.532 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2020-09-25 15:37:50.536 UTC [20] LOG:  database system was shut down at 2020-09-25 15:37:49 UTC
postgres_1  | 2020-09-25 15:37:50.540 UTC [1] LOG:  database system is ready to accept connections

任何线索都会有帮助。提前谢谢你。