docker-library / ghost

Docker Official Image packaging for Ghost
https://hub.docker.com/_/ghost
MIT License
720 stars 311 forks source link

Updating from 5.0.1 -> 5-alpine seems to wipe the entire database? #401

Closed samr28 closed 8 months ago

samr28 commented 8 months ago

Hey I've been working on updating my ghost instances from an older v4 to the latest v5. I am already running mysql (I read that there are issues switching from mysqlite but that doesn't apply to my case)

Instructions and some issues I've read say to update to the latest minor version which I did fine but then when going from tag 4-alpine to 5-alpine, it first fails to connect to the database. But if I manually specify the database connection info via environment variables, the database gets wiped (see logs below of it creating all new tables in mysql). Luckily I have backups so I restored back to one of those and tried updating the tag to 5.0.1-alpine which worked completely fine. I then stepped through each minor version up to 5.5.1-alpine and they all worked fine. I then went for it and upgraded to 5-alpine which broke once again, failing to connect to the database. When I manually specified the database connection params, it created the new tables once again.

(I have removed sensitive creds and the name of my site/url) original docker-compose.yml

version: '3'

services:
  ghost:
    image: ghost:4-alpine
    container_name: mysite-ghost
    hostname: ghost
    volumes:
      - ./ghost/content:/var/lib/ghost/content:z
    ports:
      - 3008:2368
    environment:
      - NODE_ENV=production
      - url=https://mysite.com
      - mail__transport="SMTP"
      - mail__from=REMOVED
      - mail__options__service="SMTP"
      - mail__options__host=REMOVED
      - mail__options__port=REMOVED
      - mail__options__auth__user="apikey"
      - mail__options__auth__pass=REMOVED
    restart: always
    links:
      - db

  db:
    image: mysql:8
    container_name: mysite-mysql
    volumes:
      - ./dbdata:/var/lib/mysql:z
    environment:
      - MYSQL_ROOT_PASSWORD=REMOVED
      - MYSQL_DATABASE=ghostdata
      - MYSQL_USER=ghostusr
      - MYSQL_PASSWORD=REMOVED
    restart: always

new docker-compose.yaml original docker-compose.yml

version: '3'

services:
  ghost:
    image: ghost:5-alpine
    container_name: mysite-ghost-5a
    hostname: ghost
    volumes:
      - ./ghost/content:/var/lib/ghost/content:z
    ports:
      - 3008:2368
    environment:
      - NODE_ENV=production
      - url=https://mysite.com
      - database__client="mysql"
      - database__connection__host="db"
      - database__connection__user="ghostusr"
      - database__connection__password=REMOVED
      - database__connection__database="ghostdata"
      - mail__transport="SMTP"
      - mail__from=REMOVED
      - mail__options__service="SMTP"
      - mail__options__host=REMOVED
      - mail__options__port=REMOVED
      - mail__options__auth__user="apikey"
      - mail__options__auth__pass=REMOVED
    restart: always
    links:
      - db

  db:
    image: mysql:8
    container_name: mysite-mysql-5a
    volumes:
      - ./dbdata:/var/lib/mysql:z
    environment:
      - MYSQL_ROOT_PASSWORD=REMOVED
      - MYSQL_DATABASE=ghostdata
      - MYSQL_USER=ghostusr
      - MYSQL_PASSWORD=REMOVED
    restart: always

Here's the first logs, failing to connect to the database

mysite-ghost | [2023-12-27 18:35:54] INFO Ghost is running in production...
mysite-ghost | [2023-12-27 18:35:54] INFO Your site is now available on https://mysite.com/
mysite-ghost | [2023-12-27 18:35:54] INFO Ctrl+C to shut down
mysite-ghost | [2023-12-27 18:35:54] INFO Ghost server started in 0.69s
mysite-ghost | [2023-12-27 18:35:54] ERROR connect ECONNREFUSED 127.0.0.1:3306
mysite-ghost | 
mysite-ghost | connect ECONNREFUSED 127.0.0.1:3306
mysite-ghost | 
mysite-ghost | "Unknown database error"
mysite-ghost | 
mysite-ghost | Error ID:
mysite-ghost |     500
mysite-ghost | 
mysite-ghost | Error Code: 
mysite-ghost |     ECONNREFUSED
mysite-ghost | 
mysite-ghost | ----------------------------------------
mysite-ghost | 
mysite-ghost | Error: connect ECONNREFUSED 127.0.0.1:3306
mysite-ghost |     at /var/lib/ghost/versions/5.23.0/node_modules/knex-migrator/lib/database.js:57:19
mysite-ghost |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16)
mysite-ghost | 
mysite-ghost | [2023-12-27 18:35:54] WARN Ghost is shutting down
mysite-ghost | [2023-12-27 18:35:54] WARN Ghost has shut down
mysite-ghost | [2023-12-27 18:35:54] WARN Your site is now offline
mysite-ghost | [2023-12-27 18:35:54] WARN Ghost was running for a few seconds

And when using the second compose yaml, wiping the db:

mysite-ghost-5a | [2023-12-27 18:42:19] INFO Ghost is running in production...
mysite-ghost-5a | [2023-12-27 18:42:19] INFO Your site is now available on https://mysite.com/
mysite-ghost-5a | [2023-12-27 18:42:19] INFO Ctrl+C to shut down
mysite-ghost-5a | [2023-12-27 18:42:19] INFO Ghost server started in 0.728s
mysite-ghost-5a | [2023-12-27 18:42:20] WARN Database state requires initialisation.
mysite-ghost-5a | [2023-12-27 18:42:20] INFO Creating table: newsletters
mysite-ghost-5a | [2023-12-27 18:42:20] INFO Creating table: posts
mysite-ghost-5a | [2023-12-27 18:42:20] INFO Creating table: posts_meta
mysite-ghost-5a | [2023-12-27 18:42:20] INFO Creating table: users
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: posts_authors
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: roles
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: roles_users
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: permissions
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: permissions_users
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: permissions_roles
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: settings
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: tags
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: posts_tags
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: invites
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: brute
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: sessions
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: integrations
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: webhooks
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: api_keys
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: mobiledoc_revisions
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: post_revisions
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: members
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: products
mysite-ghost-5a | [2023-12-27 18:42:21] INFO Creating table: offers
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: benefits
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: products_benefits
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_products
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: posts_products
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_created_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_cancel_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_payment_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_login_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_email_change_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_status_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_product_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_paid_subscription_events
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: labels
mysite-ghost-5a | [2023-12-27 18:42:22] INFO Creating table: members_labels
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: members_stripe_customers
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: subscriptions
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: members_stripe_customers_subscriptions
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: members_subscription_created_events
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: offer_redemptions
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: members_subscribe_events
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: stripe_products
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: stripe_prices
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: actions
mysite-ghost-5a | [2023-12-27 18:42:23] INFO Creating table: emails
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: email_batches
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: email_recipients
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: tokens
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: snippets
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: custom_theme_settings
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: members_newsletters
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: comments
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: comment_likes
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: comment_reports
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: jobs
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: redirects
mysite-ghost-5a | [2023-12-27 18:42:24] INFO Creating table: members_click_events
mysite-ghost-5a | [2023-12-27 18:42:25] INFO Creating table: members_feedback
mysite-ghost-5a | [2023-12-27 18:42:25] INFO Model: Product
mysite-ghost-5a | [2023-12-27 18:42:25] INFO Model: Newsletter
mysite-ghost-5a | [2023-12-27 18:42:25] INFO Model: Tag
mysite-ghost-5a | [2023-12-27 18:42:25] INFO Model: Permission
mysite-ghost-5a | [2023-12-27 18:42:26] INFO Model: Post
mysite-ghost-5a | [2023-12-27 18:42:26] INFO Model: Integration
mysite-ghost-5a | [2023-12-27 18:42:26] INFO Relation: Role to Permission
mysite-ghost-5a | [2023-12-27 18:42:27] INFO Relation: Post to Tag
mysite-ghost-5a | [2023-12-27 18:42:27] INFO Database is in a ready state.
mysite-ghost-5a | [2023-12-27 18:42:27] INFO Ghost database ready in 8s
mysite-ghost-5a | [2023-12-27 18:42:29] INFO Ghost URL Service Ready in 10.785s
mysite-ghost-5a | [2023-12-27 18:42:29] INFO Adding one off inline job to the queue
mysite-ghost-5a | [2023-12-27 18:42:29] INFO Stripe not configured - skipping migrations
mysite-ghost-5a | [2023-12-27 18:42:30] INFO Adding offloaded job to the queue
mysite-ghost-5a | [2023-12-27 18:42:30] INFO Scheduling job clean-expired-comped at 46 5 0 * * *. Next run on: Thu Dec 28 2023 00:05:46 GMT+0000 (Coordinated Universal Time)
mysite-ghost-5a | [2023-12-27 18:42:30] INFO Ghost booted in 11.35s
mysite-ghost-5a | [2023-12-27 18:42:30] INFO Adding offloaded job to the queue
mysite-ghost-5a | [2023-12-27 18:42:30] INFO Scheduling job update-check at 46 54 6 * * *. Next run on: Thu Dec 28 2023 06:54:46 GMT+0000 (Coordinated Universal Time)
tianon commented 8 months ago

Hmm, that's odd for sure -- when updating from 4.x to 5.x, did you first make sure to update to the most recent 4.x? (per https://ghost.org/docs/update-major-version/#update-to-the-latest-minor-version)

Beyond that, I don't have many ideas. :see_no_evil: