1

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 terminal log

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 terminal with active django running

another terminal where i try connect to django server

when i run docker-compose.yaml file docker-compose ps output is: docker-compose ps

sudo netstat -tulpn screenshot enter image description here

oscurodrago
  • 788
  • 1
  • 8
  • 18

3 Answers3

0

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
MoiioM
  • 1,914
  • 1
  • 10
  • 16
  • by default postgres uses port 5432 anyway even if i add ports: - 5432:5432 to docker-compose.yaml the problem is the same ... seem docker-compose dosen't work... i can't reach it at http://192.168.1.30:8080 .... – oscurodrago Jul 19 '21 at 09:50
  • Your initial error was "192.168.1.38" and accepting TCP/IP connections on port 5432? You need to expose it from your compose like your docker run command – MoiioM Jul 19 '21 at 09:57
  • Where the error "192.168.1.38" and accepting TCP/IP connections on port 5432 comes from ? – MoiioM Jul 19 '21 at 09:58
  • the error come from pgAdmin when i try to connect after i used docker-compose -f docker-compose.yaml up -d as i wrote if i don't use docker-compose but just i run the container with postgres image i'ts work fine.... i belive is a docker-compose problem... it's blocks any connection – oscurodrago Jul 19 '21 at 11:10
  • What is your setup PgAdmin on your computer and adminer + postgres on the raspberry ? what's the output of `docker-compose ps` ? – MoiioM Jul 19 '21 at 11:44
  • pgadmin have default setting for both test adn same username password and db .....postgress + admier is autogenerated by docker-compose.yaml docker-compose ps output is postgres_adminer_1 entrypoint.sh docker-php-e ... Up 0.0.0.0:8080->8080/tcp,:::8080->8080/tcp postgres_db_1 docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp,:::5432->5432/tcp – oscurodrago Jul 19 '21 at 11:59
  • It's strange what's the result of `netstat -tulpn` ? – MoiioM Jul 19 '21 at 15:02
  • Added netstat -tulpn response as screehshot in main question https://i.stack.imgur.com/ktq2U.jpg – oscurodrago Jul 19 '21 at 15:12
  • Can you run the command as root ? to be sure docker-compose don't bind ports. – MoiioM Jul 19 '21 at 15:19
  • ofcourse ! updated screenshot on question – oscurodrago Jul 19 '21 at 17:32
  • Your postgres instance is not exposed but the adminer yes. You can check the logs of postgres with the command `docker-compose logs db` – MoiioM Jul 20 '21 at 07:34
  • You'd be horrified to find out how long I spent fruitlessly looking up various "solutions" to this exact problem, before I realised I had "MySQL" rather than "PostgreSQL" selected in the Adminer sign-in page. :( – Neil Barnwell Feb 09 '23 at 16:13
-1

a little late to the party but what you need to do is figure out the IP address of the postgres container, and use that as your host.

-1

I just had the same issue than you. I think you probably solved it today but here is what I did:

docker-compose stop
docker-compose down

# It's probably overkill but we never know
docker system prune --all

docker-compose up

Then I went back to adminer, http://localhost:8080 and filled in the form and it worked.

I found the solution here: https://stackoverflow.com/a/56150504

FYI, here is my docker-compose file:

version: '3'

services:
  web:
    build:
      context: ./client
    environment:
      REACT_APP_API_URL: 'http://localhost:3000'
    ports:
      - "5173:5173"
    tty: true
    stdin_open: true
    volumes:
      - ./client:/web
  api:
    build:
      context: ./server
    depends_on:
      - db
      - adminer
      - amqp
    ports:
      - "3000:3000"
    tty: true
    stdin_open: true
    volumes:
      - ./server:/api
  db:
    image: postgres:15.2
    environment:
      POSTGRES_PASSWORD: example
      POSTGRES_USER: example
      POSTGRES_DB: example
    ports:
      - "5432:5432"
  adminer:
    image: adminer
    ports:
      - "8080:8080"
  amqp:
    image: rabbitmq:3.11-management
    ports:
      - "5672:5672"
      - "15672:15672"
tdimnet
  • 1
  • 1