postgresql 无法从dbeaver访问postgres docker

soat7uwm  于 2024-01-07  发布在  PostgreSQL
关注(0)|答案(2)|浏览(152)

Docker Desktop 4.21.1(114176)
docker-compose文件:

# Use postgres/example user/password credentials
version: 'latest'

services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: dbadmin
      POSTGRES_PASSWORD: mypassword
      POSTGRES_DB: testdb       
    volumes:
       - /Volumes/Development/directories/workspace/postgres/data:/var/lib/postgresql/data

  adminer:
    image: adminer
    restart: always
    ports:
      - 9080:9080

字符串
Docker容器正确启动:

postgres % docker-compose up
[+] Running 2/0
 ✔ Container postgres-db-1       Created                                                                                                                                                 0.0s 
 ✔ Container postgres-adminer-1  Created                                                                                                                                                 0.0s 
Attaching to postgres-adminer-1, postgres-db-1
postgres-adminer-1  | [Mon Aug 14 15:07:53 2023] PHP 7.4.33 Development Server (http://[::]:8080) started
postgres-db-1       | 
postgres-db-1       | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres-db-1       | 
postgres-db-1       | 
postgres-db-1       | 2023-08-14 15:07:53.174 UTC [1] LOG:  starting PostgreSQL 15.4 (Debian 15.4-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
postgres-db-1       | 2023-08-14 15:07:53.174 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres-db-1       | 2023-08-14 15:07:53.174 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres-db-1       | 2023-08-14 15:07:53.177 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-db-1       | 2023-08-14 15:07:53.194 UTC [30] LOG:  database system was shut down at 2023-08-14 15:07:29 UTC
postgres-db-1       | 2023-08-14 15:07:53.205 UTC [1] LOG:  database system is ready to accept connections
postgres-db-1       | 2023-08-14 15:12:53.200 UTC [28] LOG:  checkpoint starting: time
postgres-db-1       | 2023-08-14 15:12:53.250 UTC [28] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.011 s, sync=0.012 s, total=0.051 s; sync files=2, longest=0.010 s, average=0.006 s; distance=0 kB, estimate=0 kB


sql命令按预期返回数据(但我想知道为什么它没有提示输入密码

p950ojb@MOSF2N57RL7VD postgres % docker ps                        
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                              NAMES
a4de0010b9e3   postgres   "docker-entrypoint.s…"   33 minutes ago   Up 34 seconds   5432/tcp                           postgres-db-1
c7a25633ca1f   adminer    "entrypoint.sh php -…"   37 minutes ago   Up 34 seconds   8080/tcp, 0.0.0.0:9080->9080/tcp   postgres-adminer-1
p950ojb@MOSF2N57RL7VD postgres % 
p950ojb@MOSF2N57RL7VD postgres % docker exec -it a4de0010b9e3 bash
root@a4de0010b9e3:/# 
root@a4de0010b9e3:/# psql -d testdb -U dbadmin
psql (15.4 (Debian 15.4-1.pgdg120+1))
Type "help" for help.

testdb=# select * from accounts;
 id | username 
----+----------
  1 | rick
  2 | morty
(2 rows)


现在,当我试图通过DBeaver连接时,我点击“测试连接”,它被拒绝:x1c 0d1x
另外,http://localhost:9080没有按照Docker postgres page上的建议显示:
运行docker stack deploy -c stack.yml postgres(或docker-compose -f stack.yml up),等待它完全初始化,然后访问http://swarm-ip:8080、http://localhost:8080或http://host-ip:8080(根据需要)。

67up9zun

67up9zun1#

PostgreSQL的端口5432在docker外部不可见,除非你导出它(就像你已经对adminer的端口9080做的那样)。你必须将以下行添加到你的docker-compose.yml

ports:                                                                                                                                         
  - 5432:5432

字符串

ygya80vv

ygya80vv2#

我在DBeaver中删除了数据库名称,突然它工作了


的数据

相关问题