简体   繁体   中英

Docker Postgres and Adminer accept connection but doesn't work

On my rasperry pi 4 I've installed docker and docker-compose and now I'm tring to install and use Postgres and Adminer following that https://hub.docker.com/_/postgres I've created docker-compose.yaml file as follow:

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

services:

  db:
    image: postgres
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
    ports:
      - 5432:5432

  adminer:
    image: adminer
    restart: unless-stopped
    ports:
      - 8080:8080

and i run it with

docker-compose -f docker-compose.yaml up -d

after that DB_1 starts and adminer too but when i try connect to http://192.168.1.38:8080/ i can't reach it even if i try connect to postgres through pgAdmin it's says 终端日志

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "192.168.1.38" and accepting TCP/IP connections on port 5432?

however if i don't use docker-compose but just

docker run --name postgres -d --restart unless-stopped -p 5432:5432 -e POSTGRES_PASSWORD=123456 -v ${PWD}/data:/var/lib/postgresql/data postgres

it's work through pgAdmin

do you know what i'm doing wrong?

UPDATE: seems the problem is with docker-compose because any kind of docker-compose.yml file block connection to it...

with a container with djgango i tried to start server and it's works but when i try reach page it seem bloccked too运行活动 django 的终端

我尝试连接到 django 服务器的另一个终端

when i run docker-compose.yaml file docker-compose ps output is: 码头工人撰写ps

sudo netstat -tulpn screenshot 在此处输入图像描述

PgAdmin can't reach 5432 ports because you don't expose it. Like for Adminer you need to expose the Postgres port 5432 on your machine in your compose file.

version: '3.1'

services:

  db:
    image: postgres
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
    ports:
      - 5432:5432

  adminer:
    image: adminer
    restart: unless-stopped
    ports:
      - 8080:8080

聚会有点晚了,但您需要做的是找出 postgres 容器的 IP 地址,并将其用作您的主机。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM