Chapter 17: Creating the Ghost Project with Docker Compose
Now that Docker and Docker Compose are installed and working, it’s time to deploy your blog platform — Ghost!
Ghost is modern, fast, and perfect for personal blogs or professional content. With Docker Compose, you’ll have it running in just a few commands.
Step 1: Create the Project Directory
We’ll keep everything organized in one folder.
mkdir ~/ghost
cd ~/ghost
Step 2: Create the docker-compose.yml
File
Inside the ~/ghost
folder, create the file:
vim docker-compose.yml
version: '3.8' # Compose file format version
services:
ghost:
image: ghost:5-alpine # Use Ghost CMS version 5 based on Alpine Linux (lightweight)
container_name: ghost # Name the container "ghost"
restart: always # Automatically restart the container if it crashes or the server reboots
ports:
- 8080:2368 # Map host port 8080 to container port 2368 (Ghost default)
environment:
url: https://root.hexacats.cloud # Public URL where Ghost will be accessible
database__client: mysql # Database type: MySQL
database__connection__host: dockerlab-mariadb # Hostname of the MariaDB/MySQL container
database__connection__user: ghostuser # Database username
database__connection__password: <db_password> # Database password (replace with real one)
database__connection__database: ghost # Database name to be used by Ghost
NODE_ENV: production # Run in production mode
mail: '{"transport":"SMTP","options":{"host":"smtp.gmail.com","port":587,"secure":false,"auth":{"user":"<mail_account>","pass":"<mail_password>"}},"from":"mail_account"}'
# Mail settings in JSON format for sending emails via Gmail SMTP
volumes:
- ghost-data:/var/lib/ghost/content # Persist Ghost content (images, themes, etc.) in a named volume
networks:
- dockerlab-network # Attach this container to an external network for communication with the DB
volumes:
ghost-data: # Define the named volume used to persist Ghost content
networks:
dockerlab-network:
external: true # Use an existing Docker network named "dockerlab-network"
Replace yourdomain.com
with your actual domain.
docker-compose up -d # Start the container in detached mode
docker ps # Check running containers