Connecting to Google Cloud SQL from Ghost deployed to App Engine with Dockerfile

I was following this tutorial to deploy Ghost to Google App Engine
https://cloud.google.com/community/tutorials/ghost-on-app-engine-part-1-deploying

However, the approach of installing Ghost as an NPM Module has been deprecated.

This tutorial introduced a method of installing Ghost with a Dockerfile. https://vanlatum.dev/ghost-appengine/

I’m trying to deploy Ghost to Google App Engine by utilizing this Dockerfile, and connect to my Google Cloud SQL database.

However I’m getting the issue:

ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2019-10-03 21:10:46] ERROR connect ENOENT /cloudsql/ghost

connect ENOENT /cloudsql/ghost

"Unknown database error"

Error ID:
    500

Error Code:
    ENOENT

----------------------------------------

DatabaseError: connect ENOENT /cloudsql/ghost
    at DatabaseError.KnexMigrateError (/var/lib/ghost/versions/2.31.1/node_modules/knex-migrator/lib/errors.js:7:26)

In the first tutorial it mentions needing to run a migration before starting ghost to prevent this issue. So I’ve tried adding this line in my Dockerfile

RUN npm install knex-migrator --no-save
RUN NODE_ENV=production node_modules/knex-migrator init --mgpath node_modules/ghost

But then I get the following error:

/bin/sh: 1: node_modules/knex-migrator: Permission denied
The command '/bin/sh -c NODE_ENV=production node_modules/knex-migrator init --mgpath node_modules/ghost' returned a non-zero code: 126

How can I configure my Dockerfile to migrate the database before running Ghost to ensure it can connect to the Cloud SQL database?

Files:

Dockerfile

FROM ghost

COPY config.production.json /var/lib/ghost/config.production.json
WORKDIR /var/lib/ghost
COPY credentials.json /var/lib/ghost/credentials.json
RUN npm install ghost-gcs --no-save
WORKDIR /var/lib/ghost/content/adapters/storage/ghost-gcs/
ADD https://raw.githubusercontent.com/thomas-vl/ghost-gcs/master/export.js index.js

WORKDIR /var/lib/ghost

config.production.json

{
  "url": "https://redactedurl.appspot.com",
  "fileStorage": false,
  "mail": {},
  "database": {
    "client": "mysql",
    "connection": {
      "socketPath": "/cloudsql/ghost",
      "user": "redacted",
      "password": "redacted",
      "database": "ghost",
      "charset": "utf8"
    },
    "debug": false
  },
  "server": {
    "host": "0.0.0.0",
    "port": "2368"
  },
  "paths": {
    "contentPath": "content/"
  },
  "logging": {
    "level": "info",
    "rotation": {
      "enabled": true
    },
    "transports": ["file", "stdout"]
  },
  "storage": {
    "active": "ghost-gcs",
    "ghost-gcs": {
      "key": "credentials.json",
      "bucket": "redactedurl"
    }
  }
}

app.yaml

runtime: custom
service: blog
env: flex
manual_scaling:
  instances: 1
env_variables:
  MYSQL_USER: redacted
  MYSQL_PASSWORD: redacted
  MYSQL_DATABASE: ghost
  INSTANCE_CONNECTION_NAME: redacted:us-central1:ghost
beta_settings:
  cloud_sql_instances: redacted:us-central1:ghost
skip_files:
  - ^(.*/)?#.*#$
  - ^(.*/)?.*~$
  - ^(.*/)?.*.py[co]$
  - ^(.*/)?.*/RCS/.*$
  - ^(.*/)?..*$
  - ^(.*/)?.*.ts$
  - ^(.*/)?config.development.json$

``

Source: StackOverflow