composebuilder

Docker Compose: Ghost + MySQL

Run the Ghost publishing platform with MySQL 8.4 in Docker Compose, with persistent content storage, a database healthcheck and a production checklist.

When to use this stack

This stack runs Ghost, an open source publishing platform for blogs, newsletters and paid memberships, with MySQL 8.4 as its database. Ghost keeps posts, members and settings in MySQL and stores images and themes in a content folder. Compose keeps both parts in sync: the database starts first, Ghost waits until it answers, and both data locations live in named volumes so that a container update does not erase the site. It is a practical way to self-host a publication you can back up and move.

Choose it when you want a focused publishing tool with a clean editor and built-in newsletter features, and you are comfortable running a Linux server. It works well for a personal blog, a company news site, or a paid newsletter on a single VPS. Do not choose it when you need a large multi-site network or heavy custom application logic, where a full framework is a better base. Ghost also expects a working mail provider for member emails, and this file does not configure one, so plan that before you launch.

The Ghost image already contains the application, so this compose file does not build anything. The only persistent data is the MySQL database and the /var/lib/ghost/content folder, which holds images, media and themes. Ghost reads its database settings from environment variables that use double underscores, such as database__connection__host, which is the documented way to set nested options in the image.

docker-compose.yml

services:
  ghost:
    image: ghost:5-alpine
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
    ports:
      - "2368:2368"
    environment:
      url: ${GHOST_URL}
      database__client: mysql
      database__connection__host: mysql
      database__connection__port: 3306
      database__connection__user: ${MYSQL_USER}
      database__connection__password: ${MYSQL_PASSWORD}
      database__connection__database: ${MYSQL_DATABASE}
    volumes:
      - ghost_content:/var/lib/ghost/content

  mysql:
    image: mysql:8.4
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u root -p$$MYSQL_ROOT_PASSWORD --silent"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s

volumes:
  ghost_content:
  mysql_data:

.env

.env
# Public address of the site, with scheme and no trailing slash
GHOST_URL=http://localhost:2368
# MySQL root password, used only inside the mysql container
MYSQL_ROOT_PASSWORD=CHANGE_ME_root_password
# Database and user that Ghost connects with
MYSQL_DATABASE=ghost
MYSQL_USER=ghost
MYSQL_PASSWORD=CHANGE_ME_ghost_db_password

Start and verify

Shell
docker compose config --quiet

# Start the database and then Ghost
docker compose up -d

# mysql must show "healthy" before ghost starts
docker compose ps

# Read the Ghost log for "Ghost is running" and any database errors
docker compose logs --tail=50 ghost

# The public site and the admin login page should answer
curl -I http://localhost:2368
curl -I http://localhost:2368/ghost/

After the checks pass, open http://localhost:2368/ghost in a browser and create the owner account.

Production checklist

  • Serve Ghost over HTTPS with a reverse proxy such as Caddy, which can request certificates automatically, and set GHOST_URL to the HTTPS address.
  • Configure a transactional mail service in the Ghost settings or with the mail__* variables, so member sign-up and password emails are delivered.
  • Keep the MySQL port unpublished, which this file already does, and use a strong MYSQL_PASSWORD.
  • Back up the mysql_data volume with mysqldump and archive ghost_content, because images and themes live there.
  • Pin ghost:5-alpine and mysql:8.4, and read the release notes before any upgrade. Ghost upgrades can require newer database versions.
  • Enable the Ghost backup or export feature in the admin area, and store exports outside the server.
  • Restrict the /ghost admin path at the proxy with extra authentication or an IP allow list if the site is for one editor.

Common problems

  • Symptom: Ghost shows “Database connection failed” at start. Cause: The database is still starting or the credentials do not match. Fix: Check that mysql is healthy, then compare the MYSQL_* values with the database__connection__* settings and run docker compose up -d.
  • Symptom: Images load from localhost after you deploy. Cause: GHOST_URL still uses localhost. Fix: Set the public URL in .env and run docker compose up -d ghost to recreate the container.
  • Symptom: Changing MYSQL_PASSWORD in .env does nothing. Cause: The MySQL user is created only when the mysql_data volume is first initialized. Fix: Change the password with ALTER USER inside MySQL, then update .env to match. Use docker compose down -v only on an empty test install.
  • Symptom: Uploaded images disappear after a container update. Cause: The content folder was not stored in a volume. Fix: Confirm that ghost_content is mounted at /var/lib/ghost/content in the compose file.
  • Symptom: The site works but member emails never arrive. Cause: No mail provider is configured. Fix: Add the mail settings in Ghost or in compose and send a test email from the admin panel.

Variations

  • Caddy in front with HTTPS: Add a caddy:2 service that publishes ports 80 and 443 and proxies to ghost:2368. Remove the public 2368 mapping so only the proxy is reachable from the outside.
  • Ghost with MariaDB: Replace mysql with mariadb:11.4 and keep the same database settings. Ghost supports MySQL-compatible databases, but test the restore and upgrade path before you switch.
  • Separate staging site: Copy the compose file to another folder, change the project name with -p, use another published port such as 2369, and point GHOST_URL at the staging address.

Questions

Where is the Ghost admin panel?

The admin panel is at /ghost on the URL set in GHOST_URL, for example http://localhost:2368/ghost. You create the first owner account there the first time you open it.

Why does Ghost say the URL is wrong after I deploy?

The url setting must match the public address with the correct scheme. If GHOST_URL still says localhost, links and assets point to the wrong place. Change GHOST_URL in .env and recreate the ghost container.

Which MySQL version works with Ghost?

Ghost 5 is documented for MySQL 8.0. This file uses mysql:8.4 with a fixed tag. Check the Ghost release notes before you upgrade either side.

Adapt this stack

Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.

Open in builder
  • WordPress + MySQL + phpMyAdmin

    Run WordPress with MySQL 8.4 and phpMyAdmin in Docker Compose, with persistent volumes, healthchecks, a local-only admin panel and a production checklist.

    • wordpress
    • mysql
    • phpmyadmin
    Difficulty: Beginner
  • Directus + PostgreSQL

    Run Directus 11 headless CMS on PostgreSQL 16 in Docker Compose, with required keys, admin bootstrap, persistent uploads, a health check and a checklist.

    • directus
    • db
    Difficulty: Intermediate
  • Django + PostgreSQL + Celery

    Run a Django app with Gunicorn, PostgreSQL 16, Redis 7 as the Celery broker and a Celery worker in Docker Compose, with healthchecks and a production checklist.

    • web
    • worker
    • db
    • redis
    Difficulty: Advanced
  • Laravel + PostgreSQL + Redis

    Run a Laravel app on Apache with PostgreSQL 16 and Redis 7 in Docker Compose, with a Dockerfile, queue and cache settings, volumes and a production checklist.

    • app
    • db
    • redis
    Difficulty: Intermediate

Browse more Web & Frameworks stacks or the full library.