botpress from hub.docker start in PostgreDB

885 views Asked by At

I want to use botpress with PostgreSQL.

Found on https://hub.docker.com/r/botpress/server

example

docker run --detach \
           --name=botpress \
           --publish 3000:8080 \
           --volume botpress_data:/botpress/data \
           --env  PORT=8080 \ # Don't forget to adjust "--publish" then
           --env  BP_HOST=0.0.0.0 \ # all zeroes means listen to all interfaces
           --env  NODE_ENV=production \
           --env  PG_HOST=192.168.0.11 \
           --env  PG_PORT=5432 \
           --env  PG_USER=bp_user \
           --env  PG_PASSWORD=<********> \
           --env  PG_SSL=false \
           botpress/server:latest

In my local env I run in Docker PostgreSQL

0d530862c5c3        postgres                      "docker-entrypoint.s…"   6 weeks ago         Up 38 minutes              0.0.0.0:54320->5432/tcp             postgresql_inclouds

In this DB I create user botpress and DB botpress and granted all privelegies to botpress user.

enter image description here

after I start in docker botpress

docker run --detach \
--name=botpres \
--net=inclouds_network \
--publish 3000:3000 \
--volume /opt/docker/botpress:/botpress/data \
--env BP_HOST=0.0.0.0 \
--env NODE_ENV=production \
--env PG_HOST=postgresql_inclouds \
--env PG_PORT=5432 \
--env PG_USER=botpress \
--env PG_PASSWORD=b0tpress \
--env PG_SSL=false \
botpress/server:v12_10_7

docker container with botpress started

webGUI is working

enter image description here

But botpress working with SQLite.

How to make it work with PostgreSQL DB?

2

There are 2 answers

0
Leonardo Jauregui On BEST ANSWER

If you need or want to use docker compose for botpress along with postgres there are a few things to keep in mind.

The docker-compose.yaml file:

  • The connection to postgre must be made in the .env file inside the container, for that we must map the file using a volume and place it in the correct location as shown in the service that I have called "botpressserver"

    version: '3'
    services:
       postgres:
          image: postgres:12
          restart: always
          ports:
              - '0.0.0.0:5432:5432'
          volumes:
              - C:/your-docker-folder/Botpress/postgres:/var/lib/postgresql/data
          environment:
              - POSTGRES_DB=botpress
              - POSTGRES_USER=bp_user
              # Please provide your own password.
              - POSTGRES_PASSWORD=your-postgres-user-password
    
    
      pgadmin:
          image: dpage/pgadmin4
          depends_on:
              - postgres
          volumes:
              - C:/your-docker-folder/Botpress/pgadmin:/var/lib/pgadmin
          ports:
              - "0.0.0.0:5555:5555"
          environment:
              PGADMIN_DEFAULT_EMAIL: define-your-pgadmin-user
              PGADMIN_DEFAULT_PASSWORD: define-your-pgadmin-admin-password
          restart: unless-stopped
    
      botpressserver:
          container_name: botpress
          depends_on:
              - postgres
          ports:
              - '8703:3000' # or change 8703 to your prefered access port
          volumes:
              - 'C:/your-docker-folder/Botpress/.env:/botpress/.env'
              - 'C:/your-docker-folder/Botpress/botpress_data:/botpress/data'
          environment:
              - BP_CONFIG_HTTPSERVER_HOST=botpressserver
              - NODE_ENV=production
              - PG_HOST=postgres
              - PG_PORT=5432
              - PG_USER=bp_user
              - 'PG_PASSWORD=your-postgres-user-password'
              - PG_SSL=false
          image: 'botpress/server:latest'
    

The .env file: In my case has 2 variables, the name of the database, and the connection string. Remember this file must be mapped by a volume to this location within the container

  • 'C:/your-docker-folder/Botpress/.env:/botpress/.env'

    DATABASE=botpress
    DATABASE_URL=postgres://bp_user:your-postgres-user-password@postgres:5432/botpress

Database conexion string sintax:


    postgres://{postgres_user}:{postgres_user_password}@{postgres_host_OR_docker_service_name}:{postgres_port}/{postgres_database_name}

Run it and enjoy it ;)

PD:I hope I can help someone

1
Flash On

Most of these variables can be set in the configuration file data/global/botpress.config.json. Infrastructure configuration (like the database, cluster mode, etc) isn't available in the configuration file, since it is required before the config is loaded.

Botpress supports .env files.

You have to set the Environment Variables in the ".env" file and restart the Botpress service with the new variables.

DATABASE=postgres

DATABASE_URL=postgres://login:password@host:port/database

Example:

DATABASE=postgres
DATABASE_URL=postgres://johnlogin:[email protected]:5432/botpressdb

The ".env" file has to be located in the same directory with the "bp" executable file.

I started the botpress service as a node.js by pm2 utility without Docker.

And I used the command:

pm2 reload 0 --update-env

You can try to add the same environment variables in the docker run command.

After all, you can check the correct settings in the Botpress menu "Production checklist"