thingsboard / thingsboard.github.io

Documentation repository
Apache License 2.0
122 stars 301 forks source link

Missing information/config for postgres from docker linux installation guide #428

Open pomali opened 3 years ago

pomali commented 3 years ago

This is a...

Problem: Documentation for Docker for Linux/Mac is missing information about postgres https://thingsboard.io/docs/user-guide/install/docker/?ubuntuThingsboardQueue=inmemory

When you are installing based on this documentation you have no idea that there should be postgres installed somewhere, it is missing from "Prerequisites" and there is no mention about it in text. So you end up with org.postgresql.util.PSQLException: FATAL: database "thingsboard" does not exist error.

Proposed Solution:

Based on issue https://github.com/thingsboard/thingsboard/issues/3347 there is example docker-compose.yml that has postgres included which fixes problem with missing postgres.

docker-compose.yml

version: '2.2'
services:
  mytbpe:
    restart: always
    image: "thingsboard/tb-postgres"
    ports:
      - "8080:9090"
      - "1883:1883"
      - "5683:5683/udp"
    environment:
      TB_QUEUE_TYPE: in-memory
      SPRING_DATASOURCE_USERNAME: postgres
      SPRING_DATASOURCE_PASSWORD: postgres
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/thingsboard
    volumes:
      - ~/.mytb-data:/data
      - ~/.mytb-logs:/var/log/thingsboard
  postgres:
    restart: always
    image: "postgres:11.6"
    ports:
    - "5432"
    environment:
      POSTGRES_DB: thingsboard
      POSTGRES_PASSWORD: postgres
    volumes:
      - ~/.mytb-data/db:/var/lib/postgresql/data

Page to Update: https://thingsboard.io/docs/user-guide/install/docker/?ubuntuThingsboardQueue=inmemory

I don't mid creating PR but wasn't sure that this is preferred solution

PL4typus commented 3 years ago

Can confirm that following instructions doesn't lead to success.

Also, using the thingsboard/tb image with embedded HSQLDB database doesn't work with the docker command provided.

PL4typus commented 3 years ago

@pomali I tried the provided docker-compose.yml file and get the following error:

Starting thingsboard_postgres_1 ... done
Recreating thingsboard_mytbpe_1 ... done
Attaching to thingsboard_postgres_1, thingsboard_mytbpe_1
postgres_1  | 
postgres_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1  | 
postgres_1  | 2020-12-16 16:00:54.943 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2020-12-16 16:00:54.943 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2020-12-16 16:00:54.959 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2020-12-16 16:00:55.001 UTC [26] LOG:  database system was shut down at 2020-12-16 15:58:10 UTC
postgres_1  | 2020-12-16 16:00:55.008 UTC [1] LOG:  database system is ready to accept connections
mytbpe_1    | psql: could not connect to server: No such file or directory
mytbpe_1    |   Is the server running locally and accepting
mytbpe_1    |   connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

How can this be fixed ? Thanks for your time.

pomali commented 3 years ago

This looks like if mytbpe_1 isn't reading environment variables and is trying to connect using sockets instead of network. But I don't remember, if I had some similar problem. I would check if YAML has correct indentation and if mytbpe_1 is getting environment set.

PL4typus commented 3 years ago

It does read environment variables, apparently:

$ docker-compose run mytbpe /bin/bash
Starting thingsboard_postgres_1 ... done
thingsboard@cf53e2d73fc3:/$ echo $SPRING_DATASOURCE_URL
jdbc:postgresql://postgres:5432/thingsboard

I tried touching up the docker-compose.yml file, with no success so far:

version: "3.4"                                                                                                                                                               
services:
    mytbpe:
        restart: always
        image: "thingsboard/tb-postgres"
        depends_on:
            - postgres
        ports:
            - "8080:9090"
            - "1883:1883"
            - "5683:5683/udp"
        environment:
            - TB_QUEUE_TYPE=in-memory
            - SPRING_DATASOURCE_USERNAME=postgres
            - SPRING_DATASOURCE_PASSWOR= postgres
            - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/thingsboard
        volumes:
            - ~/.mytb-data:/data
            - ~/.mytb-logs:/var/log/thingsboard

    postgres:
        restart: always
        image: "postgres:11.6"
        ports:
            - "5432"
        environment:
            - POSTGRES_DB=thingsboard
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
        volumes:
            - ~/.mytb-data/db:/var/lib/postgresql/data

I added a depends_on to make sure that the database container starts first.

PL4typus commented 3 years ago

Also, adding more specifically to this issue: there are instructions here that are completely different from what's currently in documentation. Or maybe I missed something?

wodz commented 3 years ago

I had it working once with docker-compolse.yml as above. Then I wanted to upgrade to 3.2 and it failed. Removing volumes and recreating doesn't solve the problem as well. I also get thingsboard_1 | psql: could not connect to server: No such file or directory thingsboard_1 | Is the server running locally and accepting thingsboard_1 | connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? Docs are still not updated https://thingsboard.io/docs/user-guide/install/docker/

woland7 commented 3 years ago

Still not updated.

dreaquil commented 3 years ago

Still not updated. Can we get some clarity on what is the correct way to install using Docker?

dreaquil commented 3 years ago

Hi Bogdan,

It seems you have removed your reply from this issue. Can you update on the plan for this please?

Kind regards,

André

On Thu, Jun 3, 2021 at 10:24 AM Bogdan @.***> wrote:

Hello everyone.

I'm confirm this case. Working on fix.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/thingsboard/thingsboard.github.io/issues/428#issuecomment-853725925, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHXU6I2RT65VWV6TCEINLBLTQ5C3XANCNFSM4SMYIFXQ .

--

Regards,

André

trypzz commented 3 years ago

Hi Bogdan, It seems you have removed your reply from this issue. Can you update on the plan for this please? Kind regards, André On Thu, Jun 3, 2021 at 10:24 AM Bogdan @.***> wrote: Hello everyone. I'm confirm this case. Working on fix. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#428 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHXU6I2RT65VWV6TCEINLBLTQ5C3XANCNFSM4SMYIFXQ . -- Regards, André

Hello, yes.

I'm confirm problems with docker image. Postgres cant initialize the database inside of container. Waiting for news from our developers.

dreaquil commented 3 years ago

Hi @trypzz,

Is there any progress on this? or any intermediate suggestion please?

trypzz commented 3 years ago

Hi @trypzz,

Is there any progress on this? or any intermediate suggestion please?

Temporary you can change permission on docker.sock by this command sudo chmod 666 /var/run/docker.sock and try to start docker-compose, but this is not right and you can get some security problems. I did not recommend to use this at production, but this works.