skip to Main Content

Docker Desktop 4.21.1 (114176)

docker-compose file:

# 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 containers start up correctly:

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

The sql command returns data as expected(but I am wondering why it didn’t prompt for the password)

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)

Now when I tried to connect via DBeaver, and I click on ‘Test connection’, it is refused:
enter image description here

also http://localhost:9080 isn’t displayed as suggested on the Docker postgres page:

Run docker stack deploy -c stack.yml postgres (or docker-compose -f
stack.yml up), wait for it to initialize completely, and visit
http://swarm-ip:8080, http://localhost:8080, or http://host-ip:8080
(as appropriate).

2

Answers


  1. PostgreSQL’s port 5432 is not visible outside of docker unless you export it (as you have already done with adminer’s port 9080). You have to add the follwing lines to your docker-compose.yml:

    ports:                                                                                                                                         
      - 5432:5432                                                                                                                                  
    
    Login or Signup to reply.
  2. I removed the database name in DBeaver and suddenly it worked

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search