Fully Automating My Blog with Ghost + MySQL + Nginx + SSL in Docker Compose
A Ghost blog installation guide even non-developers can follow. A detailed explanation of setting up Ghost, MySQL, Nginx and SSL all at once with Docker Compose — the whole process from environment setup to automatic HTTPS, based on a real example.
This post shows how to build a Ghost blog in one go on Docker, together with a MySQL database, an Nginx reverse proxy and free SSL certificate issuance. Once you understand the Docker Compose file, it isn't hard to follow, and even if you're not a developer — like me — you can set up an environment to run a personal blog reliably.
1. Overview of the Whole Structure
Here's the setup we'll use:
- Ghost: the blog engine
- MySQL: the data store Ghost uses
- Nginx + Let's Encrypt: a proxy server with automatic HTTPS
- Docker Compose: runs the whole setup above with a single command
Each component is isolated as a service, and the necessary settings are injected through a .env file.
2. docker-compose.yml
version: '3.9'
services:
nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: nginx-proxy
ports:
- 80:80
- 443:443
volumes:
- ./certs:/etc/nginx/certs:ro
- ./vhost:/etc/nginx/vhost.d
- ./html:/usr/share/nginx/html
- ./conf:/etc/nginx/conf.d
- /var/run/docker.sock:/tmp/docker.sock:ro
restart: unless-stopped
nginx-proxy-acme:
image: nginxproxy/acme-companion
container_name: nginx-proxy-acme
depends_on:
- nginx-proxy
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
volumes:
- ./certs:/etc/nginx/certs:rw
- ./acme:/etc/acme.sh
- ./vhost:/etc/nginx/vhost.d
- ./html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: unless-stopped
ghost:
image: ghost:5
container_name: ghost
depends_on:
- db
environment:
NODE_ENV: production
url: https://${DOMAIN}
VIRTUAL_HOST: ${DOMAIN}
VIRTUAL_PORT: 2368
LETSENCRYPT_HOST: ${DOMAIN}
LETSENCRYPT_EMAIL: ${EMAIL}
MAIL__TRANSPORT: ${MAIL_TRANSPORT}
MAIL__OPTIONS__SERVICE: ${MAIL_SERVICE}
MAIL__OPTIONS__AUTH__USER: ${MAIL_USER}
MAIL__OPTIONS__AUTH__PASS: ${MAIL_PASS}
database__client: mysql
database__connection__host: db
database__connection__user: ${MYSQL_USER}
database__connection__password: ${MYSQL_PASSWORD}
database__connection__database: ${MYSQL_DATABASE}
volumes:
- ./ghost-data:/var/lib/ghost/content
restart: unless-stopped
db:
image: mysql:8.0.42
container_name: ghost-mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- ./db-data:/var/lib/mysql
restart: unless-stopped
volumes:
ghost-data:
db-data:
certs:
vhost:
html:
acme:
conf:3. Each Service in Detail
Now let's break it down service by service so even beginners can follow.
✅ 3.1 nginx-proxy: The Reverse Proxy
- Image:
nginxproxy/nginx-proxy - Role: receives incoming HTTP/HTTPS requests from outside and forwards them to the right container based on the domain name.
- Port settings:
ports:
- 80:80
- 443:443→ Handles requests from browsers connecting via http:// (80) or https:// (443).
- Volumes
- ./certs:/etc/nginx/certs:ro
- ./vhost:/etc/nginx/vhost.d
- ./html:/usr/share/nginx/html
- ./conf:/etc/nginx/conf.d
- /var/run/docker.sock:/tmp/docker.sock:rocerts: SSL certificate storagedocker.sock: reads container info to generate proxy configuration automatically
✅ 3.2 nginx-proxy-acme: Automatic SSL Certificates
- Image:
nginxproxy/acme-companion - Role: issues Let's Encrypt SSL certificates and renews them automatically.
- Key environment variable
NGINX_PROXY_CONTAINER: nginx-proxy→ Tells it which container is the proxy.
- Certificate storage: saved under
./certs
✅ 3.3 ghost: The Blog Itself
- Image:
ghost:5 - Key environment variables
VIRTUAL_HOST: ${DOMAIN}
LETSENCRYPT_HOST: ${DOMAIN}
LETSENCRYPT_EMAIL: ${EMAIL}→ Thanks to these values, nginx-proxy and acme-companion handle SSL issuance & proxy configuration automatically.
- Data storage:
volumes:
- ./ghost-data:/var/lib/ghost/content→ Blog content is preserved in the ./ghost-data folder.
✅ 3.4 db: The MySQL Database
- Image:
mysql:8.0.42 - Environment variables:
MYSQL_ROOT_PASSWORD
MYSQL_DATABASE
MYSQL_USER
MYSQL_PASSWORD- Data storage:
volumes:
- ./db-data:/var/lib/mysql4. Writing the .env File
Create a .env file so sensitive information isn't exposed.
DOMAIN=blog.example.com
[email protected]
MYSQL_ROOT_PASSWORD=mysecret
MYSQL_DATABASE=ghostdb
MYSQL_USER=ghost
MYSQL_PASSWORD=ghostpw
MAIL_TRANSPORT=SMTP
MAIL_SERVICE=Gmail
[email protected]
MAIL_PASS=app-password5. How to Run It
docker compose up -d-doption: runs in the background- All services run as containers, and SSL certificates are issued automatically.
6. First Access & Ghost Initial Setup
Open https://<DOMAIN>/ghost in your browser → go through Ghost's initial setup.
Once mail authentication is set up too, you're fully ready to run your blog!
✅ Key Points for Beginners
- Docker volumes → data is preserved even if you delete the container
- Environment variables (.env) → to change settings, edit only
.env - nginx-proxy + acme → fully automated SSL certificates
- docker compose up -d → every service runs with one line