linuxserver / docker-bookstack

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

Bookstack fails to run because of failing migrations on clean run #125

Closed irslon closed 2 years ago

irslon commented 2 years ago

linuxserver.io


Expected Behavior

Bookstack should start on a clean environment.

Current Behavior

Bookstack fails to run migrations, and thus fails to start the application.

bookstack       | Migrating: 2018_08_04_115700_create_bookshelves_table
bookstack       | Migrated:  2018_08_04_115700_create_bookshelves_table (1,288.78ms)
bookstack       | Migrating: 2019_07_07_112515_add_template_support
bookstack       |
bookstack       |    Illuminate\Database\QueryException
bookstack       |
bookstack       |   SQLSTATE[HY000] [2002] Connection refused (SQL: alter table `pages` add index `pages_template_index`(`template`))
bookstack       |
bookstack       |   at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
bookstack       |     708▕         // If an exception occurs when attempting to run a query, we'll format the error
bookstack       |     709▕         // message to include the bindings with SQL, which will make this exception a
bookstack       |     710▕         // lot more helpful to the developer instead of just the database's errors.
bookstack       |     711▕         catch (Exception $e) {
bookstack       |   ➜ 712▕             throw new QueryException(
bookstack       |     713▕                 $query, $this->prepareBindings($bindings), $e
bookstack       |     714▕             );
bookstack       |     715▕         }
bookstack       |     716▕     }
bookstack       |
bookstack       |       +18 vendor frames
bookstack       |   19  /var/www/html/database/migrations/2019_07_07_112515_add_template_support.php:20
bookstack       |       Illuminate\Support\Facades\Facade::__callStatic()
bookstack       |
bookstack       |       +22 vendor frames
bookstack       |   42  /var/www/html/artisan:37
bookstack       |       Illuminate\Foundation\Console\Kernel::handle()
bookstack       | [cont-init.d] 50-config: exited 0.
bookstack       | [cont-init.d] 90-custom-folders: executing...
bookstack       | [cont-init.d] 90-custom-folders: exited 0.
bookstack       | [cont-init.d] 99-custom-files: executing...
bookstack       | [custom-init] no custom files found exiting...
bookstack       | [cont-init.d] 99-custom-files: exited 0.
bookstack       | [cont-init.d] done.
bookstack       | [services.d] starting services
bookstack       | [services.d] done.

Steps to Reproduce

  1. create docker-compose.yaml file:
    ---
    version: "2"
    services:
    bookstack:
    image: lscr.io/linuxserver/bookstack
    container_name: bookstack
    environment:
      - PUID=1000
      - PGID=1000
      - APP_URL=
      - DB_HOST=bookstack_db
      - DB_USER=bookstack
      - DB_PASS=<yourdbpass>
      - DB_DATABASE=bookstackapp
    volumes:
      - /path/to/data:/config
    ports:
      - 6875:80
    restart: unless-stopped
    depends_on:
      - bookstack_db
    bookstack_db:
    image: lscr.io/linuxserver/mariadb
    container_name: bookstack_db
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=<yourdbpass>
      - TZ=Europe/London
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=<yourdbpass>
    volumes:
      - /path/to/data:/config
    restart: unless-stopped
  2. docker-compose up

Environment

OS: Windows 11 CPU architecture: x86_64 How docker service was installed: Docker Desktop

Command used to create docker container (run/create/compose/screenshot)

compose as seen above.

Docker logs

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01-envfile: executing...
[cont-init.d] 01-envfile: exited 0.
[cont-init.d] 02-tamper-check: executing...
[cont-init.d] 02-tamper-check: exited 0.
[cont-init.d] 10-adduser: executing...
usermod: no changes

-------------------------------------
          _         ()
         | |  ___   _    __
         | | / __| | |  /  \
         | | \__ \ | | | () |
         |_| |___/ |_|  \__/

Brought to you by linuxserver.io
-------------------------------------

To support LSIO projects visit:
https://www.linuxserver.io/donate/
-------------------------------------
GID/UID
-------------------------------------

User uid:    1000
User gid:    1000
-------------------------------------

[cont-init.d] 10-adduser: exited 0.
[cont-init.d] 20-config: executing...
[cont-init.d] 20-config: exited 0.
[cont-init.d] 30-keygen: executing...
generating self-signed keys in /config/keys, you can replace these with your own keys if required
Generating a RSA private key
.........................+++++
......+++++
writing new private key to '/config/keys/cert.key'
-----
[cont-init.d] 30-keygen: exited 0.
[cont-init.d] 50-config: executing...
Generating BookStack app key for first run
App Key set to base64:4wwkR78IDF3a6ADF+piwCT1NGrzpxjRwpuU7SQXsedI= you can modify the file to update /config/BOOKSTACK_APP_KEY.txt
Running config - db_user set
**** Docker env var APP_URL is not set, setting it to http://37.190.246.141:6875 ****
**** APP_URL in /config/www/.env is being updated from https://example.com to http://37.190.246.141:6875 ****
**** If this is an existing install, you should run the following line from your host terminal to update the database URL entries: ****
************************************************************************
docker exec -it bookstack php /var/www/html/artisan bookstack:update-url https://example.com http://37.190.246.141:6875
************************************************************************
/var/run/s6/etc/cont-init.d/50-config: line 98: warning: command substitution: ignored null byte in input
/var/run/s6/etc/cont-init.d/50-config: line 98: warning: command substitution: ignored null byte in input
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (281.85ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (126.82ms)
Migrating: 2015_07_12_114933_create_books_table
Migrated:  2015_07_12_114933_create_books_table (39.22ms)
Migrating: 2015_07_12_190027_create_pages_table
Migrated:  2015_07_12_190027_create_pages_table (35.55ms)
Migrating: 2015_07_13_172121_create_images_table
Migrated:  2015_07_13_172121_create_images_table (31.96ms)
Migrating: 2015_07_27_172342_create_chapters_table
Migrated:  2015_07_27_172342_create_chapters_table (29.59ms)
Migrating: 2015_08_08_200447_add_users_to_entities
Migrated:  2015_08_08_200447_add_users_to_entities (110.03ms)
Migrating: 2015_08_09_093534_create_page_revisions_table
Migrated:  2015_08_09_093534_create_page_revisions_table (28.35ms)
Migrating: 2015_08_16_142133_create_activities_table
Migrated:  2015_08_16_142133_create_activities_table (26.12ms)
Migrating: 2015_08_29_105422_add_roles_and_permissions
Migrated:  2015_08_29_105422_add_roles_and_permissions (1,094.71ms)
Migrating: 2015_08_30_125859_create_settings_table
Migrated:  2015_08_30_125859_create_settings_table (130.09ms)
Migrating: 2015_08_31_175240_add_search_indexes
Migrated:  2015_08_31_175240_add_search_indexes (0.13ms)
Migrating: 2015_09_04_165821_create_social_accounts_table
Migrated:  2015_09_04_165821_create_social_accounts_table (109.35ms)
Migrating: 2015_09_05_164707_add_email_confirmation_table
Migrated:  2015_09_05_164707_add_email_confirmation_table (195.80ms)
Migrating: 2015_11_21_145609_create_views_table
Migrated:  2015_11_21_145609_create_views_table (40.72ms)
Migrating: 2015_11_26_221857_add_entity_indexes
Migrated:  2015_11_26_221857_add_entity_indexes (834.95ms)
Migrating: 2015_12_05_145049_fulltext_weighting
Migrated:  2015_12_05_145049_fulltext_weighting (0.11ms)
Migrating: 2015_12_07_195238_add_image_upload_types
Migrated:  2015_12_07_195238_add_image_upload_types (148.84ms)
Migrating: 2015_12_09_195748_add_user_avatars
Migrated:  2015_12_09_195748_add_user_avatars (31.21ms)
Migrating: 2016_01_11_210908_add_external_auth_to_users
Migrated:  2016_01_11_210908_add_external_auth_to_users (66.68ms)
Migrating: 2016_02_25_184030_add_slug_to_revisions
Migrated:  2016_02_25_184030_add_slug_to_revisions (86.12ms)
Migrating: 2016_02_27_120329_update_permissions_and_roles
Migrated:  2016_02_27_120329_update_permissions_and_roles (179.57ms)
Migrating: 2016_02_28_084200_add_entity_access_controls
Migrated:  2016_02_28_084200_add_entity_access_controls (367.52ms)
Migrating: 2016_03_09_203143_add_page_revision_types
Migrated:  2016_03_09_203143_add_page_revision_types (74.73ms)
Migrating: 2016_03_13_082138_add_page_drafts
Migrated:  2016_03_13_082138_add_page_drafts (79.42ms)
Migrating: 2016_03_25_123157_add_markdown_support
Migrated:  2016_03_25_123157_add_markdown_support (61.43ms)
Migrating: 2016_04_09_100730_add_view_permissions_to_roles
Migrated:  2016_04_09_100730_add_view_permissions_to_roles (79.53ms)
Migrating: 2016_04_20_192649_create_joint_permissions_table
Migrated:  2016_04_20_192649_create_joint_permissions_table (500.34ms)
Migrating: 2016_05_06_185215_create_tags_table
Migrated:  2016_05_06_185215_create_tags_table (214.33ms)
Migrating: 2016_07_07_181521_add_summary_to_page_revisions
Migrated:  2016_07_07_181521_add_summary_to_page_revisions (31.25ms)
Migrating: 2016_09_29_101449_remove_hidden_roles
Migrated:  2016_09_29_101449_remove_hidden_roles (140.57ms)
Migrating: 2016_10_09_142037_create_attachments_table
Migrated:  2016_10_09_142037_create_attachments_table (137.61ms)
Migrating: 2017_01_21_163556_create_cache_table
Migrated:  2017_01_21_163556_create_cache_table (111.10ms)
Migrating: 2017_01_21_163602_create_sessions_table
Migrated:  2017_01_21_163602_create_sessions_table (113.43ms)
Migrating: 2017_03_19_091553_create_search_index_table
Migrated:  2017_03_19_091553_create_search_index_table (424.12ms)
Migrating: 2017_04_20_185112_add_revision_counts
Migrated:  2017_04_20_185112_add_revision_counts (117.98ms)
Migrating: 2017_07_02_152834_update_db_encoding_to_ut8mb4
Migrated:  2017_07_02_152834_update_db_encoding_to_ut8mb4 (0.12ms)
Migrating: 2017_08_01_130541_create_comments_table
Migrated:  2017_08_01_130541_create_comments_table (158.85ms)
Migrating: 2017_08_29_102650_add_cover_image_display
Migrated:  2017_08_29_102650_add_cover_image_display (25.22ms)
Migrating: 2018_07_15_173514_add_role_external_auth_id
Migrated:  2018_07_15_173514_add_role_external_auth_id (71.57ms)
Migrating: 2018_08_04_115700_create_bookshelves_table
Migrated:  2018_08_04_115700_create_bookshelves_table (1,288.78ms)
Migrating: 2019_07_07_112515_add_template_support

   Illuminate\Database\QueryException

  SQLSTATE[HY000] [2002] Connection refused (SQL: alter table `pages` add index `pages_template_index`(`template`))

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

      +18 vendor frames
  19  /var/www/html/database/migrations/2019_07_07_112515_add_template_support.php:20
      Illuminate\Support\Facades\Facade::__callStatic()

      +22 vendor frames
  42  /var/www/html/artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
[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.
[services.d] starting services
[services.d] done.
Signal handled: Terminated.`
github-actions[bot] commented 2 years ago

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

ssddanbrown commented 2 years ago

It this consistent? What occurs on restart of the containers?

irslon commented 2 years ago

It this consistent? What occurs on restart of the containers?

Yes, it is consistent. After restart of containers, bookstack tries to retry the missing migrations without any success.

Starting bookstack_db ... done
Starting bookstack    ... done
Attaching to bookstack_db, bookstack
bookstack_db    | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
bookstack_db    | [s6-init] ensuring user provided files have correct perms...exited 0.
bookstack_db    | [fix-attrs.d] applying ownership & permissions fixes...
bookstack_db    | [fix-attrs.d] done.
bookstack_db    | [cont-init.d] executing container initialization scripts...
bookstack_db    | [cont-init.d] 01-envfile: executing...
bookstack_db    | [cont-init.d] 01-envfile: exited 0.
bookstack_db    | [cont-init.d] 02-tamper-check: executing...
bookstack_db    | [cont-init.d] 02-tamper-check: exited 0.
bookstack_db    | [cont-init.d] 10-adduser: executing...
bookstack_db    | usermod: no changes
bookstack_db    |
bookstack_db    | -------------------------------------
bookstack_db    |           _         ()
bookstack_db    |          | |  ___   _    __
bookstack_db    |          | | / __| | |  /  \
bookstack_db    |          | | \__ \ | | | () |
bookstack_db    |          |_| |___/ |_|  \__/
bookstack_db    |
bookstack_db    |
bookstack_db    | Brought to you by linuxserver.io
bookstack_db    | -------------------------------------
bookstack_db    |
bookstack_db    | To support LSIO projects visit:
bookstack_db    | https://www.linuxserver.io/donate/
bookstack_db    | -------------------------------------
bookstack_db    | GID/UID
bookstack_db    | -------------------------------------
bookstack_db    |
bookstack_db    | User uid:    1000
bookstack_db    | User gid:    1000
bookstack_db    | -------------------------------------
bookstack_db    |
bookstack_db    | [cont-init.d] 10-adduser: exited 0.
bookstack_db    | [cont-init.d] 30-config: executing...
bookstack_db    | [cont-init.d] 30-config: exited 0.
bookstack_db    | [cont-init.d] 40-initialise-db: executing...
bookstack_db    | [cont-init.d] 40-initialise-db: exited 0.
bookstack_db    | [cont-init.d] 90-custom-folders: executing...
bookstack_db    | [cont-init.d] 90-custom-folders: exited 0.
bookstack_db    | [cont-init.d] 99-custom-files: executing...
bookstack_db    | [custom-init] no custom files found exiting...
bookstack_db    | [cont-init.d] 99-custom-files: exited 0.
bookstack_db    | [cont-init.d] done.
bookstack_db    | [services.d] starting services
bookstack_db    | [services.d] done.
bookstack_db    | 220613 20:11:08 mysqld_safe Logging to '/config/databases/182390000fb5.err'.
bookstack_db    | 220613 20:11:08 mysqld_safe Starting mariadbd daemon with databases from /config/databases
bookstack       | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
bookstack       | [s6-init] ensuring user provided files have correct perms...exited 0.
bookstack       | [fix-attrs.d] applying ownership & permissions fixes...
bookstack       | [fix-attrs.d] done.
bookstack       | [cont-init.d] executing container initialization scripts...
bookstack       | [cont-init.d] 01-envfile: executing...
bookstack       | [cont-init.d] 01-envfile: exited 0.
bookstack       | [cont-init.d] 02-tamper-check: executing...
bookstack       | [cont-init.d] 02-tamper-check: exited 0.
bookstack       | [cont-init.d] 10-adduser: executing...
bookstack       | usermod: no changes
bookstack       |
bookstack       | -------------------------------------
bookstack       |           _         ()
bookstack       |          | |  ___   _    __
bookstack       |          | | / __| | |  /  \
bookstack       |          | | \__ \ | | | () |
bookstack       |          |_| |___/ |_|  \__/
bookstack       |
bookstack       |
bookstack       | Brought to you by linuxserver.io
bookstack       | -------------------------------------
bookstack       |
bookstack       | To support LSIO projects visit:
bookstack       | https://www.linuxserver.io/donate/
bookstack       | -------------------------------------
bookstack       | GID/UID
bookstack       | -------------------------------------
bookstack       |
bookstack       | User uid:    1000
bookstack       | User gid:    1000
bookstack       | -------------------------------------
bookstack       |
bookstack       | [cont-init.d] 10-adduser: exited 0.
bookstack       | [cont-init.d] 20-config: executing...
bookstack       | [cont-init.d] 20-config: exited 0.
bookstack       | [cont-init.d] 30-keygen: executing...
bookstack       | using keys found in /config/keys
bookstack       | [cont-init.d] 30-keygen: exited 0.
bookstack       | [cont-init.d] 50-config: executing...
bookstack       | App Key found - setting variable for seds
bookstack       | Running config - db_user set
bookstack       | **** Docker env var APP_URL is not set, setting it to http://37.190.246.141:6875 ****
bookstack       | /var/run/s6/etc/cont-init.d/50-config: line 98: warning: command substitution: ignored null byte in input
bookstack       | /var/run/s6/etc/cont-init.d/50-config: line 98: warning: command substitution: ignored null byte in input
bookstack       | Migrating: 2019_07_07_112515_add_template_support
bookstack       |
bookstack       |    Illuminate\Database\QueryException
bookstack       |
bookstack       |   SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'template' (SQL: alter table `pages` add `template` tinyint(1) not null default '0')
bookstack       |
bookstack       |   at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
bookstack       |     708▕         // If an exception occurs when attempting to run a query, we'll format the error
bookstack       |     709▕         // message to include the bindings with SQL, which will make this exception a
bookstack       |     710▕         // lot more helpful to the developer instead of just the database's errors.
bookstack       |     711▕         catch (Exception $e) {
bookstack       |   ➜ 712▕             throw new QueryException(
bookstack       |     713▕                 $query, $this->prepareBindings($bindings), $e
bookstack       |     714▕             );
bookstack       |     715▕         }
bookstack       |     716▕     }
bookstack       |
bookstack       |       +9 vendor frames
bookstack       |   10  /var/www/html/database/migrations/2019_07_07_112515_add_template_support.php:20
bookstack       |       Illuminate\Support\Facades\Facade::__callStatic()
bookstack       |
bookstack       |       +22 vendor frames
bookstack       |   33  /var/www/html/artisan:37
bookstack       |       Illuminate\Foundation\Console\Kernel::handle()
bookstack       | [cont-init.d] 50-config: exited 0.
bookstack       | [cont-init.d] 90-custom-folders: executing...
bookstack       | [cont-init.d] 90-custom-folders: exited 0.
bookstack       | [cont-init.d] 99-custom-files: executing...
bookstack       | [custom-init] no custom files found exiting...
bookstack       | [cont-init.d] 99-custom-files: exited 0.
bookstack       | [cont-init.d] done.
bookstack       | [services.d] starting services
bookstack       | [services.d] done.
thespad commented 2 years ago

I've not been able to replicate this with either a new container or upgrading an existing one on a Linux host but a couple of people have reported the same issue specifically on Windows.

irslon commented 2 years ago

I've not been able to replicate this with either a new container or upgrading an existing one on a Linux host but a couple of people have reported the same issue specifically on Windows.

You are correct. After using the same config on linux host the problem disappears.

bthaase commented 2 years ago

I just tried to spin up the example Docker compose file on top of Docker Desktop for Windows, got the exact same result. Migration failure with the exact same stack trace. Have yet to find a workaround.

ssddanbrown commented 2 years ago

I'd very roughly guess there's potentially an issue with the filesystem not keeping up with DB changes.

irslon commented 2 years ago

I'd very roughly guess there's potentially an issue with the filesystem not keeping up with DB changes.

* Does it work if you don't mount any volumes for the DB container?

Your guess is right. Mounting the Windows directory to a volume breaks the migration. When I use internal docker volume with default driver it works flawlessly on Windows.

Working example configuration for Windows:

---
version: "2"
services:
  bookstack:
    image: lscr.io/linuxserver/bookstack
    container_name: bookstack
    environment:
      - PUID=1000
      - PGID=1000
      - APP_URL=
      - DB_HOST=bookstack_db
      - DB_USER=bookstack
      - DB_PASS=bookstack
      - DB_DATABASE=bookstackapp
    volumes:
      - bookstackdata:/config
    ports:
      - 6875:80
    restart: unless-stopped
    depends_on:
      - bookstack_db
  bookstack_db:
    image: lscr.io/linuxserver/mariadb
    container_name: bookstack_db
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=bookstackroot
      - TZ=Europe/Warsaw
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=bookstack
    volumes:
      - bookstackdbdata:/config
    ports:
      - 13306:3306
    restart: unless-stopped
volumes:
  bookstackdata:
  bookstackdbdata:
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.

irslon commented 2 years ago

I would like to close this issue because of the working workaround provided by @ssddanbrown

TheCDC commented 2 years ago

I also have this issue and the workaround does make the app functional for me. It's not ideal but it's not Bookstack's fault.

j0nnymoe commented 2 years ago

I would also like to point out that it's also not an issue with our container. Its going to be now docker works on windows and we do not test our containers on windows.

takkaO commented 1 year ago

I have a same problem. I finally got around the problem by using mysql instead of marinadb. My compose.yml which I success to launch is below.

services:
  bookstack:
    image: lscr.io/linuxserver/bookstack:23.02.2
    container_name: bookstack
    environment:
      - PUID=1000
      - PGID=1000
      - APP_URL=http://192.168.0.220:6875
      - APP_DEBUG=true
      - APP_LANG=ja
      - STORAGE_TYPE=local
      - DB_HOST=bookstack_db
      - DB_PORT=3306
      - DB_USER=bookstack
      - DB_PASSWORD=12345678
      - DB_DATABASE=bookstackapp
    volumes:
      - ./bookstackdata:/config
    ports:
      - 6875:80
    restart: unless-stopped
    depends_on:
      - bookstack_db

  bookstack_db:
    #image: mariadb:10.6.12
    image: mysql:8.0.32
    container_name: bookstack_db
    ports:
      - 3306:3306
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=password
      - TZ=Asia/Tokyo
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=12345678
      - TERM=dumb
    volumes:
      - ./bookstackdbdata:/config
      - ./db-store:/var/lib/mysql
    restart: unless-stopped

Thank you.

github-actions[bot] commented 1 year ago

This issue is locked due to inactivity