Ghost is an open-source publishing platform built on modern Node.js technology, designed for teams that require robust features, flexibility, and high performance. This topic explains how to deploy Ghost using Docker Compose and connect it to OceanBase Database as the backend storage, enabling persistent storage and management of blog content.
Compatibility
- OceanBase Database version: ≥ V4.2.1
- Ghost version: ≥ 5.0
Prerequisites
Before using Ghost, ensure the following conditions are met:
- Docker and Docker Compose are installed. For installation instructions, refer to the Docker official documentation.
- OceanBase Database has been deployed and a MySQL mode user tenant has been created. For details on creating a user tenant, see Create a tenant.
Procedure
Step 1: Obtain the OceanBase Database connection string
Contact the OceanBase Database deployment personnel to obtain the connection string. For example:
obclient -h$host -P$port -u$user_name -p$password -D$database_name
Parameter description:
$host: The connection IP address. For ODP connections, use the ODP address; for direct connections, use the OBServer IP.$port: The connection port. For ODP connections, the default is2883; for direct connections, the default is2881.$database_name: The database name.Notice
The user connecting to the tenant must have the
CREATE,INSERT,DROP, andSELECTpermissions on the database. For more information about user permissions, see Permissions in MySQL mode.$user_name: The connection account. For ODP connections, the format isuser@tenant#clusterorcluster:tenant:user; for direct connections, the format isuser@tenant.$password: The account password.
For more information about the connection string, see Connect to an OceanBase tenant by using OBClient.
Example:
obclient -hxxx.xxx.xxx.xxx -P2881 -utest_user001@mysql001 -p****** -Dtest
Step 2: Create a database for Ghost
Create a database in OceanBase Database to store blog data for Ghost, for example, ghost_db.
CREATE DATABASE ghost_db;
After the execution is complete, record the database name for use in the Docker Compose configuration file.
Step 3: Create a Docker Compose configuration file
In your local working directory, create a docker-compose.yml file and configure Ghost to connect to OceanBase Database.
version: '3.8'
services:
ghost:
image: ghost:5-alpine
container_name: ghost-blog
restart: always
ports:
- "2368:2368"
environment:
database__client: mysql
database__connection__host: $host
database__connection__user: $user_name
database__connection__password: $password
database__connection__database: ghost_db
database__connection__port: $port
url: http://localhost:2368
NODE_ENV: production
volumes:
- ./ghost-content:/var/lib/ghost/content
network_mode: "bridge"
networks:
default:
external: false
Configuration parameter description:
database__client: mysql: Specifies to use the MySQL client to connect to OceanBase Database.database__connection__host: The connection address of OceanBase Database.database__connection__user: The username of OceanBase Database.database__connection__password: The password of OceanBase Database.database__connection__database: The database name (recommended:ghost_db).database__connection__port: The port of OceanBase Database.
Step 4: Deploy and start Ghost
In the directory where docker-compose.yml is located, execute the following commands to pull the image and start the Ghost service.
Pull the Ghost image:
docker compose pullStart the Ghost service:
docker compose up -d
After the commands are executed successfully, the Ghost container will start in the background.
Step 5: Access the Ghost blog
Access the homepage: In your browser, enter
http://host IP address:2368to access the Ghost homepage.Note
If you encounter a 502 error, check if the firewall within the instance is blocking the connection. You can disable the firewall.
Access the management page: In your browser, enter
http://host IP address:2368/ghostto access the Ghost management page.When you first access the Ghost management page, you need to complete the relevant configuration according to the prompts on the page. Please complete the configuration based on the actual prompts on the page.
Verification
After completing the above steps, you can verify if Ghost is running properly by following these methods:
Check the container status:
docker ps | grep ghost-blogView the container logs:
docker logs ghost-blogAccess the Ghost homepage and management page to confirm that they can be displayed and operated normally.
