Docker -无法与Postgres通话

yqhsw0fo  于 2023-02-03  发布在  Docker
关注(0)|答案(1)|浏览(128)

我正在使用docker-compose来编排两个服务,但是其中一个服务出现了错误。根据日志,下面是我的输出:

2023/02/01 08:34:35 [INFO] version.go:13 versionPrint(): starting Commento
2023/02/01 08:34:35 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2023/02/01 08:34:35 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (4 attempts left): dial tcp 172.18.0.2:5432: connect: connection refused
2023/02/01 08:34:45 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2023/02/01 08:34:45 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (3 attempts left): pq: unknown authentication response: 10
2023/02/01 08:34:55 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2023/02/01 08:34:55 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (2 attempts left): pq: unknown authentication response: 10
2023/02/01 08:35:05 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2023/02/01 08:35:06 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (1 attempts left): pq: unknown authentication response: 10
2023/02/01 08:35:16 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2023/02/01 08:35:16 [ERROR] database_connect.go:31 dbConnect(): cannot talk to postgres, retrying in 10 seconds (0 attempts left): pq: unknown authentication response: 10
2023/02/01 08:35:26 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2023/02/01 08:35:26 [ERROR] database_connect.go:35 dbConnect(): cannot talk to postgres, last attempt failed: pq: unknown authentication response: 10
fatal error: pq: unknown authentication response: 10

我还没有尝试任何解决方案,因为我不知道从哪里开始。我该如何解决这个问题?

重现步骤:

1.在干净的Ubuntu 22.04LTS服务器上,安装了docker和docker-compose。
1.为服务创建了一个目录,并对docker-compose.yml使用了以下配置:

version: '3'

services:
  server:
    image: registry.gitlab.com/commento/commento:SET_VERSION
    ports:
      - 8080:8080
    environment:
      COMMENTO_ORIGIN: http://commento.example.com:8080
      COMMENTO_PORT: 8080
      COMMENTO_POSTGRES: postgres://postgres:postgres@db:5432/commento?sslmode=disable
    depends_on:
      - db
  db:
    image: postgres
    environment:
      POSTGRES_DB: commento
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - postgres_data_volume:/var/lib/postgresql/data

volumes:
  postgres_data_volume:

1.运行docker-compose up -d,然后我跟踪了两个服务的日志,服务“commonto_server_1”产生了上面提到的输出。

6rqinv9w

6rqinv9w1#

首先,使用registry.gitlab.com/commento/commento:SET_VERSION会导致下面的错误:

Pulling server (registry.gitlab.com/commento/commento:SET_VERSION)...
ERROR: manifest for registry.gitlab.com/commento/commento:SET_VERSION not found: manifest unknown: manifest unknown

因为没有comento的SET_VERSION版本。
因此,您一定做了一些不同的事情。请在下次提问时,确保您提供的重现问题的说明是 * 最小的 * 和 * 完整的 *。请参阅https://stackoverflow.com/help/minimal-reproducible-example
无论如何,我能够重现你从commento:SET_VERSION切换到commento:latest的问题。你所面临的问题是由于comento的最新版本(在撰写本文时)不支持postgres的最新版本(在撰写本文时)。
解决方案是将postgres版本降级到13

version: '3'

services:
  db:
    image: postgres:13

(keep你的docker-compose.yml的其他行)。
另外,由于comento的未来版本可能不再支持postgres 13,所以在编写docker-composite.yml时,我建议始终指定所有服务的版本:

services:
  server:
    image: registry.gitlab.com/commento/commento:v1.4.0

相关问题