linuxserver / docker-bookstack

A Docker container for the BookStack documentation wiki
GNU General Public License v3.0
797 stars 109 forks source link

Database values are not updated #109

Closed calvinbui closed 2 years ago

calvinbui commented 3 years ago

linuxserver.io


Expected Behavior

Changing the DB_HOST, DB_DATABASE, DB_USERNAME or DB_PASSWORD values should update the /config/www/.env file values.

Current Behavior

The sed command only replaces the default values.

The script also exits successfully (0) afterwards when there is an error.

See file: See file: https://github.com/linuxserver/docker-bookstack/blob/master/root/etc/cont-init.d/50-config#L65-L68

Steps to Reproduce

  1. Change any of the DB_HOST, DB_DATABASE, DB_USERNAME or DB_PASSWORD environment values
  2. /config/www/.env is not updated to the correct value
  3. The application fails to connect

Docker logs

/var/run/s6/etc/cont-init.d/50-config: line 97: warning: command substitution: ignored null byte in input
/var/run/s6/etc/cont-init.d/50-config: line 97: warning: command substitution: ignored null byte in input

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'1.2.3.4' (using password: YES) (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE')

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDO\Exception::("SQLSTATE[HY000] [1045] Access denied for user 'bookstackuser'@'192.168.4.162' (using password: YES)")
      /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18

  2   Doctrine\DBAL\Driver\PDO\Exception::new()
      /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43

  Please use the argument -v to see more details.
[cont-init.d] 50-config: exited 0.
[cont-init.d] 90-custom-folders: executing...
[cont-init.d] 90-custom-folders: exited 0.
[cont-init.d] 99-custom-files: executing...
[custom-init] no custom files found exiting...
[cont-init.d] 99-custom-files: exited 0.
[cont-init.d] done.
github-actions[bot] commented 3 years ago

Thanks for opening your first issue here! Be sure to follow the bug or feature issue templates!

j0nnymoe commented 3 years ago

These are only designed to work on first creation of the container. If you're looking change these after deployment, you'll need to edit the .env file accordingly.

matthijsbro commented 2 years ago

I just may have found the cause. If you copied docker-compose from the readme.md here it said DB_PASS where it should be DB_PASSWORD

jonasanker commented 2 years ago

@matthijsbro From what I can see the DB_PASS variable is converted and set to the Bookstack expected DB_PASSWORD when the container is created the first time. So that would not be the cause.

See https://github.com/linuxserver/docker-bookstack/blob/master/root/etc/cont-init.d/50-config#L61

if [ "${DB_USER}" ];
    then
    echo "Running config - db_user set"
    ESCAPED_PASSWORD=$(sed -e 's/[$\/&]/\\&/g' <<< $DB_PASS)
    sed -i "s/DB_HOST=localhost/DB_HOST=${DB_HOST}/g" /config/www/.env
    sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
    sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env
    sed -i "s/DB_PASSWORD=database_user_password/DB_PASSWORD=${ESCAPED_PASSWORD}/g" /config/www/.env
fi
matthijsbro commented 2 years ago

I know very little about this. I can only conclude that the change made it work for me.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

RmigD commented 2 years ago

After banging my head for hours, using DB_PASSWORD instead of DB_PASS worked for me as well.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.