docker-library / ghost

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

DatabaseError: Access denied for user #378

Closed diminDDL closed 1 year ago

diminDDL commented 1 year ago

Trying to run the example compose file for ghost from here and getting the following errors, no matter what I try:

docker-ghost-ghost-1  | [2023-03-09 23:34:20] ERROR Access denied for user 'ghost'@'172.18.0.2' (using password: YES)
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | Access denied for user 'ghost'@'172.18.0.2' (using password: YES)
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | "Unknown database error"
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | Error ID:
docker-ghost-ghost-1  |     500
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | Error Code: 
docker-ghost-ghost-1  |     ER_ACCESS_DENIED_ERROR
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | ----------------------------------------
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | DatabaseError: Access denied for user 'ghost'@'172.18.0.2' (using password: YES)
docker-ghost-ghost-1  |     at DatabaseStateManager.getState (/var/lib/ghost/versions/4.48.9/core/server/data/db/state-manager.js:64:32)
docker-ghost-ghost-1  |     at DatabaseError.KnexMigrateError (/var/lib/ghost/versions/4.48.9/node_modules/knex-migrator/lib/errors.js:7:26)
docker-ghost-ghost-1  |     at new DatabaseError (/var/lib/ghost/versions/4.48.9/node_modules/knex-migrator/lib/errors.js:55:26)
docker-ghost-ghost-1  |     at /var/lib/ghost/versions/4.48.9/node_modules/knex-migrator/lib/database.js:57:19
docker-ghost-ghost-1  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
docker-ghost-ghost-1  |     at async DatabaseStateManager.getState (/var/lib/ghost/versions/4.48.9/core/server/data/db/state-manager.js:40:13)
docker-ghost-ghost-1  |     at async DatabaseStateManager.makeReady (/var/lib/ghost/versions/4.48.9/core/server/data/db/state-manager.js:73:25)
docker-ghost-ghost-1  |     at async initDatabase (/var/lib/ghost/versions/4.48.9/core/boot.js:69:5)
docker-ghost-ghost-1  |     at async bootGhost (/var/lib/ghost/versions/4.48.9/core/boot.js:414:9)
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | Error: Access denied for user 'ghost'@'172.18.0.2' (using password: YES)
docker-ghost-ghost-1  |     at Packet.asError (/var/lib/ghost/versions/4.48.9/node_modules/mysql2/lib/packets/packet.js:728:17)
docker-ghost-ghost-1  |     at ClientHandshake.execute (/var/lib/ghost/versions/4.48.9/node_modules/mysql2/lib/commands/command.js:29:26)
docker-ghost-ghost-1  |     at Connection.handlePacket (/var/lib/ghost/versions/4.48.9/node_modules/mysql2/lib/connection.js:456:32)
docker-ghost-ghost-1  |     at PacketParser.onPacket (/var/lib/ghost/versions/4.48.9/node_modules/mysql2/lib/connection.js:85:12)
docker-ghost-ghost-1  |     at PacketParser.executeStart (/var/lib/ghost/versions/4.48.9/node_modules/mysql2/lib/packet_parser.js:75:16)
docker-ghost-ghost-1  |     at Socket.<anonymous> (/var/lib/ghost/versions/4.48.9/node_modules/mysql2/lib/connection.js:92:25)
docker-ghost-ghost-1  |     at Socket.emit (events.js:400:28)
docker-ghost-ghost-1  |     at addChunk (internal/streams/readable.js:293:12)
docker-ghost-ghost-1  |     at readableAddChunk (internal/streams/readable.js:267:9)
docker-ghost-ghost-1  |     at Socket.Readable.push (internal/streams/readable.js:206:10)
docker-ghost-ghost-1  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
docker-ghost-ghost-1  | 
docker-ghost-ghost-1  | [2023-03-09 23:34:20] WARN Ghost is shutting down

The config file looks like this:

version: '3.1'

services:

  ghost:
    image: ghost:4-alpine
    restart: always
    ports:
      - 8080:2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__database: ghost
      database__connection__user: ghost
      database__connection__password: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: http://localhost:8080
      # contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
      #NODE_ENV: development

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_USER: ghost
      MYSQL_PASSWORD: ghost
      MYSQL_DATABASE: ghost
yosifkit commented 1 year ago

Did you at any point start the db service, stop it, and then later start it but with different environment values?

Short answer: docker-compose rm -fv (assuming you have no important data already in mysql or ghost) Long answer: https://github.com/docker-library/postgres/issues/203#issuecomment-255200501 (about postgres, but mysql behaves the same for this case)

diminDDL commented 1 year ago

Yes, I did try to change the credentials because the default example with unmodified variables has a different error related to not being able to find the db at all as far as I remember. I tried doing docker-compose rm -fv and even did a full docker system prune -a which re created the db and prompted me to add MYSQL_ROOT_PASSWORD as an environment variable. After re doing the above with the correct variables in place I still got a DatabaseError: connect ECONNREFUSED 172.20.0.2:3306 error.

diminDDL commented 1 year ago

Turns out that just waiting for a few minutes made the database finish initializing and it would connects and starts working as expected.