Guide: Migrating Your Ghost Blog to a Docker Container

Learn how to migrate your Ghost blog from a traditional file system setup to a Docker container. Step-by-step guide for a seamless transition, ensuring all your content stays intact.

Guide: Migrating Your Ghost Blog to a Docker Container

In this guide, we’ll cover how to migrate a Ghost blog from a server where it was installed directly on the file system to a new server where Ghost is hosted in a Docker container. This is the third article in our Ghost blog management series:

  1. How to Host Multiple Ghost Blogs with Docker and Nginx on One Server
  2. How to Host a Ghost Blog in a Subdirectory Instead of a Subdomain

Prerequisites

  • Access to the old server with Ghost installed directly on the file system.
  • A new server where Ghost is hosted in a Docker container (ghost-blog1).
  • SSH access to both servers.

In this example:

  • Ghost container name: ghost-blog1
  • Blog URL: https://blog.mydomain1.com

Step 1: Create a Backup on the Old Server

  1. Log in to your old server.
  2. Identify the working directory for Ghost: ghost ls
    This will display all installed Ghost instances. In this example, the working directory is /var/www/ghost.
  3. Navigate to the working directory and create a backup:
cd /var/www/ghost
ghost backup

This generates a .zip backup file (e.g., backup-from-v[version]-on-[timestamp].zip) in the content folder.

Step 2: Transfer the Backup File to the New Server

Use scp to transfer the backup file to your new server. Replace placeholders with your details:

scp -i ~/.ssh/<your_ssh_key> /var/www/ghost/content/<ghost_backup>.zip root@<remote_server_ip>:/root/docker-dir/

Step 3: Copy the Backup into the Docker Container

  1. Log in to the new server.
  2. Copy the backup file into the Ghost container:
docker cp /root/docker-dir/<ghost_backup>.zip ghost-blog1:/var/lib/ghost/

Step 4: Unzip the Backup Inside the Container

  1. Enter the Ghost container:
docker exec -it ghost-blog1 bash
  1. Navigate to the Ghost content directory:
cd /var/lib/ghost
  1. Unzip the backup into the content folder:
unzip <ghost_backup>.zip -d content

If unzip is not installed, run:

apt-get update && apt-get install -y unzip

Step 5: Import the Content

The official Ghost documentation suggests importing the JSON file directly using the ghost-cli:

ghost import content/data/<ghost_backup>.json

However, running ghost import within a Docker container may be tricky due to ghost-cli limitations. Instead, use the Ghost Admin panel to import the content:

  1. Download the JSON file to your local machine.
  2. Open the Ghost Admin panel (https://blog.mydomain1.com/ghost).
  3. Go to Settings → Import/Export → Universal Import.
  4. Upload the JSON file (e.g., <ghost_backup>.json).

Step 6: Verify the Migration

  1. Check that your blog content is live at https://blog.mydomain1.com.
  2. Log in to the Ghost Admin panel and verify that all posts, pages, and settings have been restored.

You’ve successfully migrated your Ghost blog to a Docker container!

Related articles:

How to Host Multiple Ghost Blogs on a Single Server with Docker and Nginx
Learn how to efficiently host multiple Ghost blogs on a single server using Docker, Nginx, and MySQL. This guide covers setting up a scalable, secure environment with HTTPS via Let’s Encrypt.
How to Host a Ghost Blog in a Subdirectory Instead of a Subdomain
Learn how to move your Ghost blog from a subdomain to a subdirectory to boost SEO and consolidate domain authority. Step-by-step guide using Docker and Cloudflare Workers.