Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbport error in Symphony with the default config #1203

Open
mouarflenoob opened this issue Sep 14, 2024 · 13 comments
Open

dbport error in Symphony with the default config #1203

mouarflenoob opened this issue Sep 14, 2024 · 13 comments

Comments

@mouarflenoob
Copy link

mouarflenoob commented Sep 14, 2024

Hello everyone,
I get this error when I start the docker container in Portainer :

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration CONFIGURATION] [--em EM] [--conn CONN] [--] [<version>]

**** 1/11 - Make sure /uploads folders exist ****

**** 2/11 - Create the symbolic link for the /uploads folder ****

**** 3/11 - Setting env variables ****

**** 4/11 - Migrate the database ****

11:16:54 CRITICAL  [console] Error thrown while running command "'doctrine:migration:migrate' --no-interaction --allow-no-migration --env=prod". Message: "Non-numeric env var "DB_PORT" cannot be cast to int." ["exception" => Symfony\Component\DependencyInjection\Exception\RuntimeException { …},"command" => "'doctrine:migration:migrate' --no-interaction --allow-no-migration --env=prod","message" => "Non-numeric env var "DB_PORT" cannot be cast to int."]

In EnvVarProcessor.php line 264:

                                                        

  Non-numeric env var "DB_PORT" cannot be cast to int.

I used the default config and the default .env file with the default port : 5432
I looked in the issues and didn't find a similar issue.
Do you have any idea ?

@lgwapnitsky
Copy link

Same here

@benjaminjonard
Copy link
Owner

Could you please share your .env file ? I'll try to reproduce the issue

@mouarflenoob
Copy link
Author

Here is my .env file
koillection.env.txt

@xela1601
Copy link

i have the same problem. Anyone got this resolved?

@pgalinanes
Copy link

same issue here

@benjaminjonard
Copy link
Owner

Are you using portainer as well ?

@pgalinanes
Copy link

Yes, using the default templates available in the wiki inside portainer and uploading the .env file before deploying the stack.

@benjaminjonard
Copy link
Owner

I never used Portainer before, I tried to reproduce the issue but it worked fine for me. Could you tell me how you set up Koillection ?

Here is what I did :

  • Created a Postgres container
  • Created a Koillection container
  • From Koillection container config page, I uploaded the .env file

Here is my env variables for reference :
Image

@pgalinanes
Copy link

My compose file:

version: '3'

services:
    # Koillection
    koillection:
        image: koillection/koillection
        container_name: koillection
        restart: unless-stopped
        ports:
            - 8120:80
        depends_on:
            - db
        volumes:
            - koiUploads:/uploads

    # Database : choose one of the following
    db:
        image: postgres:15
        container_name: db
        restart: unless-stopped
        environment:
            - POSTGRES_DB=koiDB
            - POSTGRES_USER=koiUser
            - POSTGRES_PASSWORD=koiPassword
        volumes:
            - "koiDB:/var/lib/postgresql/data"

    #db:
    #    image: mysql:9
    #    container_name: db       
    #    restart: unless-stopped 
    #    environment:
    #        - MYSQL_DATABASE=${DB_NAME}
    #        - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
    #    volumes:
    #        - "koiDB:/var/lib/postgresql/data"

volumes:
  koiUploads:
    driver: local
    driver_opts:
      type: "nfs"
      o: "addr=192.168.1.201,nolock,soft,rw"
      device: ":/export/Docker/Koillection/uploads"
  koiDB:
    driver: local
    driver_opts:
      type: "nfs"
      o: "addr=192.168.1.201,nolock,soft,rw"
      device: ":/export/Docker/Koillection/db"

My .env file:

########################################################################################################
#                                                WEB
#
# APP_DEBUG=1 displays detailed error message
#
# APP_SECRET is a random string used for security, you can use for example openssl rand -base64 21
# APP_SECRET is automatically generated when using Docker
#
# PHP_TZ, see possible values here https://www.w3schools.com/php/php_ref_timezones.asp
########################################################################################################

APP_DEBUG=0
APP_ENV=prod
#APP_SECRET=

HTTPS_ENABLED=1
UPLOAD_MAX_FILESIZE=50M
PHP_MEMORY_LIMIT=512M
PHP_TZ=Europe/Madrid


########################################################################################################
#                                                API
#
#
# JWT_PASSPHRASE is a random string used for security, you can use for example openssl rand -base64 21
# JWT_PASSPHRASE is automatically generated when using Docker
########################################################################################################

CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
#JWT_PASSPHRASE=

########################################################################################################
#                                                DATABASE
########################################################################################################

DB_DRIVER=pdo_pgsql
DB_NAME=koiDB
DB_HOST=db
DB_PORT=5432
DB_USER=koiUser
DB_PASSWORD=koiPassword
DB_VERSION=15

And this config makes the following error:

In koillection container:

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--no-all-or-nothing] [--configuration CONFIGURATION] [--em EM] [--conn CONN] [--] [<version>]

**** 1/11 - Make sure /uploads folders exist ****

**** 2/11 - Create the symbolic link for the /uploads folder ****

**** 3/11 - Setting env variables ****

**** 4/11 - Migrate the database ****

In EnvVarProcessor.php line 264:

                                                        

  Non-numeric env var "DB_PORT" cannot be cast to int.

And db output:

PostgreSQL Database directory appears to contain a database; Skipping initialization

2025-02-05 18:05:41.677 UTC [1] LOG:  starting PostgreSQL 16.6 (Debian 16.6-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

2025-02-05 18:05:41.681 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432

2025-02-05 18:05:41.681 UTC [1] LOG:  listening on IPv6 address "::", port 5432

2025-02-05 18:05:41.767 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

2025-02-05 18:05:42.029 UTC [29] LOG:  database system was shut down at 2025-02-04 18:31:19 UTC

2025-02-05 18:05:42.249 UTC [1] LOG:  database system is ready to accept connections

Could you share your setup so I can try to replicate? Thanks in advice

@benjaminjonard
Copy link
Owner

I think it's because you to need to tell docker to use the .env file :

koillection:
        image: koillection/koillection
        container_name: koillection
        restart: unless-stopped
        ports:
            - 80:80
        env_file:
            - .env
        depends_on:
            - db
        volumes:
            - ./volumes/koillection/uploads:/uploads

@pgalinanes
Copy link

it throws an error when deploying the stack:

env file /data/compose/98/.env not found: stat /data/compose/98/.env: no such file or directory

@benjaminjonard
Copy link
Owner

Looks like a portainer issue, can you have a look here ? portainer/portainer#8263

@pgalinanes
Copy link

after many attempts I have managed to get it to work in portainer with this compose:

version: '3'

services:
    # Koillection
    koillection:
        image: koillection/koillection
        container_name: koillection
        restart: unless-stopped

        environment:
            - APP_DEBUG=0
            - APP_ENV=prod
            - HTTPS_ENABLED=0
            - UPLOAD_MAX_FILESIZE=50M
            - PHP_MEMORY_LIMIT=512M
            - PHP_TZ=Europe/Madrid
            - CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
            - JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
            - JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
            - DB_DRIVER=pdo_pgsql
            - DB_NAME=koiDB
            - DB_HOST=koillection-db
            - DB_PORT=5432
            - DB_USER=koiUser
            - DB_PASSWORD=koiPassword
            - DB_VERSION=16
        ports:
            - 8120:80
        depends_on:
            - koillection-db
        volumes:
            - koiUploads:/uploads

    # Database : choose one of the following
    koillection-db:
        image: postgres:16
        container_name: koillection-db
        restart: unless-stopped
        user: "0:1000"
        environment:
            - PUID=0
            - PGID=1000
            - POSTGRES_DB=koiDB
            - POSTGRES_USER=koiUser
            - POSTGRES_PASSWORD=koiPassword
        volumes:
            - "koiDB:/var/lib/postgresql/data"

    #koillection-db:
    #    image: mysql:9
    #    container_name: koillection-db       
    #    restart: unless-stopped 
    #    environment:
    #        - PUID=0
    #        - PGID=1000
    #        - MYSQL_DATABASE=koiDB
    #        - MYSQL_USER=koiUser
    #        - MYSQL_PASSWORD=koiPassword
    #        - MYSQL_ROOT_PASSWORD=koiPassword
    #    volumes:
    #        - "koiDB:/var/lib/mysql"

volumes:
  koiUploads:
    #fill
  koiDB:
    #fill

I have also searched on how to backup the database, in case it would be useful for other users.

docker exec -t container_name pg_dumpall -c -U your_user > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql
//(remove containers and volumes)
cat your_dump.sql | docker exec -i container_name psql -U your_user -d postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants