docker icon indicating copy to clipboard operation
docker copied to clipboard

The service does not start if MYSQL_ROOT_PASSWORD is not especified.

Open mmartinortiz opened this issue 7 years ago • 5 comments

Situation:

I'm using an existing docker container for the database. I already created a table and a user for Wallabag. As there is no need to create a user or password on the database for Wallabag, I skipped the variable MYSQL_ROOT_PASSWORD.

Result:

Once deployed using docker-compose, the app never started. I had to remove both the user and the table for getting Wallabag working.

Expected result:

As the table and the user already existed on a running database container, I expect that Wallabag checks if the database and/or the user exist, populating the database or creating the user accordingly.

mmartinortiz avatar Sep 04 '18 09:09 mmartinortiz

+1. This issue is not only for existing database containers, but for "real" database standalone hosts as well. Maybe the POPULATE_DATABASE environment flag is related to this issue.

MySQL supports IF NOT EXISTS for both tables and databases.

simonszu avatar Feb 04 '19 13:02 simonszu

+1 on this. The Docker container should not require the root DB server password: I should be able to just hand it an empty database and a user that has full rights to that database, and let it do all the rest.

AshleyYakeley avatar Jun 30 '19 02:06 AshleyYakeley

+1.

For the time being, just omit the MYSQL_ROOT_PASSWORD environmental variable and set POPULATE_DATABASE=false as @simonszu pointed out. Make sure the SYMFONY__ENV__DATABASE__* variables are all set.

Then, in your docker container proceed with the 'normal' procedure like so:

composer install bin/console wallabag:install

I'm not a 100% sure if composer install is necessary, but at least it didn't hurt in my case.

Wizkidje avatar Jul 22 '19 13:07 Wizkidje

Since you eliminated all symfony magic with your last two commands, @Wizkidje ,it would be a nearly no-brainer to cover this logic in the entrypoint script... 🤔 Maybe I'll check when I have time..

simonszu avatar Jul 22 '19 14:07 simonszu

I admit it's a dirty fix... but I just want it to work honestly.

Anyway, did a bit of digging:

    - name: add mariadb db
      mysql_db:
        name="{{ database_name }}"
        state=present
        login_host="{{ database_host }}"
        login_port={{ database_port }}
        login_user=root
        login_password="{{ database_root_password_mariadb }}"
        encoding="utf8mb4"
      notify: run install
      when: (database_driver == 'pdo_mysql') and
            (populate_database == True)
      tags:
        - firstrun

    - name: add mariadb user
      mysql_user:
        name="{{ database_user }}"
        host=%
        password="{{ database_password }}"
        priv={{ database_name }}.*:ALL
        login_host="{{ database_host }}"
        login_port={{ database_port }}
        login_user=root
        login_password="{{ database_root_password_mariadb }}"
        state=present
      when: (database_driver == 'pdo_mysql') and
            (database_user != 'root') and
            (populate_database == True)
      tags:
        - firstrun

Those are the entries that should be extended I guess. It's always using root to run the installation and when the database user is not root, it attempts to create the user after importing the database and grant the appropriate permissions. Simplest would probably be to throw in an additional environmental variable (e.g. CREATE_MYSQL_DATABASE_USER) and a different task for that.

I don't have much time on my hands either, but I might throw in a pull request if I happen to have some time to kill over the next few days.

Wizkidje avatar Jul 22 '19 14:07 Wizkidje