In Part 1. Install with Docker we covered how to get a basic installation of Ghost running with Docker on Plesk. We will now look into fully configuring Ghost as per the documentation. Please keep an eye on this guide as it will be regularly updated.

Note: This is rather hacky. We should not be utilising root let alone modifying containers like this, but due to a very old bug in Plesk's implementation of Docker we are forced to do this.

Step 1 - Change your working directory

cd /var/lib/docker/

Step 2 - Find your container ID

With your container running, login to your server via SSH and obtain root privileges. Run docker container ls -all to print a list of running containers. You will see a column titled 'CONTAINER ID' below which you will find your Ghost container ID.

dockercontainerlsall

Step 3 - Enter the container's environment

Use docker exec -it 51a6d21b4755 bash to enter the container's environment

Step 4 - Create a temporary file

touch trackerfile123 and the exit the container's environment using exit

Step 5 - Find the temporary file to locate the container's folder

find . -name trackerfile123

This will output something similar to:

./overlay/5887230dd968af10212111a5b3f3d9036d4e86f4083424cae06e568ef744862c/upper/var/lib/ghost/trackerfile123

./overlay/5887230dd968af10212111a5b3f3d9036d4e86f4083424cae06e568ef744862c/merged/var/lib/ghost/trackerfile123

You can now delete the temporary file now since we have found the folder, rm overlay/5887230dd968af10212111a5b3f3d9036d4e86f4083424cae06e568ef744862c/upper/var/lib/ghost/trackerfile123

Step 6 - Change your working directory into the directory the container is storing its files in

cd overlay/5887230dd968af10212111a5b3f3d9036d4e86f4083424cae06e568ef744862c/merged/var/lib/ghost/

Step 7 - Modify config.production.json

Use Ghost's documentation to guide your configuration.

If you wish to connect to a MySQL database, you will have to do so using the MySQL server's IP address since Docker isolates the container's network from the host system.

Alexandr Bashurov, Technical Support Engineer at Plesk, was able to provide me with the following advice:

In order to connect to the host system's MySQL, make sure that it listens on the Docker's internal bridge interface and specify it as a MySQL host. IP address of the Docker bridge interface can be found by running ip a | grep docker. In case application cannot connect to the SQL server, it will fail and the container will stop automatically.

Here is my configuration:

{
  "url": "https://domain.com",
  "server": {
    "port": 2368,
    "host": "0.0.0.0"
  },
  "database": {
    "client": "sqlite3",
    "connection": {
      "filename": "/var/lib/ghost/content/data/ghost.db"
    }
  },
  "mail": {
    "transport": "SMTP",
    "from": "'name' <[email protected]>",
    "options": {
      "service": "Mailgun",
      "auth": {
        "user": "[email protected]",
        "pass": "Vz6OrnHkJ82wOemal4MumJPumLpJgj"
      }
    }
  },
  "logging": {
    "level": "info",
    "rotation": {
      "enabled": true,
      "count": 30,
      "period": "1d"
    },
    "transports": [
      "file",
      "stdout"
    ]
  },
  "spam": {
    "user_login": {
      "minWait": 600000,
      "maxWait": 604800000,
      "freeRetries": 3
    },
    "user_reset": {
      "minWait": 3600000,
      "maxWait": 3600000,
      "lifetime": 3600,
      "freeRetries": 3
     },
     "global_reset": {
       "minWait": 3600000,
       "maxWait": 3600000,
       "lifetime": 3600,
       "freeRetries": 3
     },
     "global_block": {
       "minWait": 3600000,
       "maxWait": 3600000,
       "lifetime": 3600,
       "freeRetries":99
     },
     "private_block": {
       "minWait": 3600000,
       "maxWait": 3600000,
       "lifetime": 3600,
       "freeRetries":99
     }
  },
  "caching": {
    "frontend": {
      "maxAge": 1800
    },
    "301": {
      "maxAge": 31536000
    },
    "customRedirects": {
      "maxAge": 31536000
    },
    "favicon": {
      "maxAge": 86400
    },
    "sitemap": {
      "maxAge": 3600
    },
    "robotstxt": {
      "maxAge": 3600
    }
  },
  "privacy": {
    "useUpdateCheck": false,
    "useGravatar": false,
    "useRpcPing": true,
    "useStructuredData": true
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/lib/ghost/content"
  }
}

I also asked Plesk support for any beta version/update on the Docker extension, Alexandr's response:

Currently, there is no ETA or beta versions of Docker extension available.

Please continue putting pressure on Plesk to release this fix so we can configure Ghost without having to resort to bad practices (using root privileges and modifying containers).


Credits:

Thanks to Raoul Kramer (@djpogo on Twitter) who inspired me to find an alternative solution, his original post: https://raoulkramer.de/install-ghost-on-plesk-onyx-vserver-with-docker/
Raoul's method didn't work for me because vi/vim was not available inside the Docker container, so I was forced to hack up this method.