v2 icon indicating copy to clipboard operation
v2 copied to clipboard

[FATAL] Unable to connect to the database: dial tcp 127.0.0.1:5432: connect: connection refused

Open philosowaffle opened this issue 3 years ago • 5 comments

I have miniflux working now. But wanted to document the issues I ran into when trying to spin up miniflux using the example basic docker compose.

Initially, I started with the example basic compose file, but a few minor changes:

version: "3.9"
  
services:
  rss: 
    image: miniflux/miniflux:latest
    container_name: rss 
    #restart: unless-stopped
    environment: 
      - TZ=America/Chicago
      - DATABASE_URL=rss-db://miniflux:secret@db/miniflux?sslmode=disable
      - RUN_MIGRATIONS=1
      - CREATE_ADMIN=1
      - ADMIN_USERNAME=admin
      - ADMIN_PASSWORD=password
      - DEBUG=1
    ports:
      - 6250:8080
    depends_on:
      - rss-db
    volumes:
      - ./data/db_socket:/socket/postgresql
    healthcheck:
      test: ["CMD", "/usr/bin/miniflux", "-healthcheck", "auto"]
    logging:
      driver: loki
  
  rss-db:
    image: postgres:latest
    container_name: rss-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=miniflux
      - POSTGRES_PASSWORD=secret
    volumes:
      - ./data/db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 10s
      start_period: 30s
    logging:
      driver: loki

The DB appeared to spin up fine, but then Miniflux was completely unable to connect. According to my DATABSE_URL, miniflux should have been trying to connect to the db using:

rss-db://miniflux:secret@db/miniflux?sslmode=disable

Notice the host name here is rss-db, which should resolve to the rss-db container on the same docker network. However, I got below error in the log file:

[FATAL] Unable to connect to the database: dial tcp 127.0.0.1:5432: connect: connection refused

I fought with that for a while, checking permissions, etc. Then gave up and decided to try connecting via socket. Here, is what the modified compose file looks like to switch to Socket connection:

version: "3.4"
  
services:
  rss: 
    image: miniflux/miniflux:latest
    container_name: rss 
    #restart: unless-stopped
    environment: 
      - TZ=America/Chicago
      - DATABASE_URL=user=postgres password=postgres dbname=miniflux2 sslmode=disable host=/socket/postgresql
      - RUN_MIGRATIONS=1
      - CREATE_ADMIN=1
      - ADMIN_USERNAME=admin
      - ADMIN_PASSWORD=password
      - DEBUG=1
    ports:
      - 6250:8080
    depends_on:
      - rss-db
    volumes:
      - ./data/db_socket:/socket/postgresql
    healthcheck:
      test: ["CMD", "/usr/bin/miniflux", "-healthcheck", "auto"]
    logging:
      driver: loki
  
  rss-db:
    image: postgres:latest
    container_name: rss-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
      - ./data/db_socket:/var/run/postgresql
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 10s
      start_period: 30s
    logging:
      driver: loki

I configured the DATABASE_URL according to the documentation. I also updated the POSTGRES_USER and POSTGRES_PASWORD to match.

This mostly worked, but I started getting a new error in the logs from miniflux:

2021-12-22 09:02:04 | [FATAL] Unable to connect to the database: pq: database "miniflux2" does not exist

Dug into the PG docker docks and made the following two changes:

  1. DATABASE_URL - set dbname to 'miniflux'
  2. POSTGRES_DB=miniflux

Below is the full compose file that finally worked for me:

version: "3.4"
  
services:
  rss: 
    image: miniflux/miniflux:latest
    container_name: rss 
    #restart: unless-stopped
    environment: 
      - TZ=America/Chicago
      - DATABASE_URL=user=postgres password=postgres dbname=miniflux sslmode=disable host=/socket/postgresql
      - RUN_MIGRATIONS=1
      - CREATE_ADMIN=1
      - ADMIN_USERNAME=admin
      - ADMIN_PASSWORD=password
      - DEBUG=1
    ports:
      - 6250:8080
    depends_on:
      - rss-db
    volumes:
      - ./data/db_socket:/socket/postgresql
    healthcheck:
      test: ["CMD", "/usr/bin/miniflux", "-healthcheck", "auto"]
    logging:
      driver: loki
  
  rss-db:
    image: postgres:latest
    container_name: rss-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=miniflux
    volumes:
      - ./data/db:/var/lib/postgresql/data
      - ./data/db_socket:/var/run/postgresql
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 10s
      start_period: 30s
    logging:
      driver: loki

Maybe I missed something in the docs along the way, but my experience was that the example basic compose file did not work.

philosowaffle avatar Dec 22 '21 15:12 philosowaffle

Feel free to close this if you want, I just wanted it documented somewhere in case others try searching for a similar problem in the issues.

philosowaffle avatar Dec 22 '21 15:12 philosowaffle

@philosowaffle After following your above steps, I'm still getting the error "Database miniflux not found", this is my docker-compose file, did I miss anything?

version: "2"

services:
  miniflux-app:
    image: miniflux/miniflux:latest
    container_name: miniflux-app
    depends_on:
      - miniflux-db
    ports:
      - 7001:8080
    environment:
      - DATABASE_URL=postgres://miguel:mypwd@miniflux-db/miniflux?sslmode=disable
      - RUN_MIGRATIONS=1
      - CREATE_ADMIN=1
      - ADMIN_USERNAME=miguel
      - ADMIN_PASSWORD=mypwd

  miniflux-db:
    image: postgres:latest
    container_name: miniflux-db
    environment:
      - POSTGRES_USER=miguel
      - POSTGRES_PASSWORD=mypwd
      - POSTGRES_DB=miniflux
    volumes:
      - /volume1/dockerdata/miniflux/db:/var/lib/postgresql/data

notflip avatar Dec 23 '21 09:12 notflip

@notflip If you've previously tried to launch the miniflux-db container, then Postgres will have created a database by default. Per their documentation the POSTGRES_DB value is only used to create a new database when another DB does not already exist. To resolve this,

  1. Spin down the containers docker-compose down
  2. Delete the contents of your mounted db folder /volume1/dockerdata/miniflux/db, based on the permissions, it may appear empty on the filesystem and you may need to use sudo to delete it
  3. Spin the containers back up docker-compose up miniflux-db

This time, when the miniflux-db container is created it should also create a new db with the name of miniflux. You should also see a log message written from the db container confirming a new db was created.

philosowaffle avatar Dec 23 '21 13:12 philosowaffle

@philosowaffle Thank you, working perfectly! And you were right about the filesystem not showing theses files, had to login using root on my NAS to see them.

notflip avatar Dec 23 '21 13:12 notflip

Thanks @philosowaffle! I was also struggling with this, but your docker compose suggestion helped me :)

mattcristal avatar Jun 11 '22 13:06 mattcristal