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.
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:
- How to Host Multiple Ghost Blogs with Docker and Nginx on One Server
- 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
- Log in to your old server.
- 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
. - 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
- Log in to the new server.
- 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
- Enter the Ghost container:
docker exec -it ghost-blog1 bash
- Navigate to the Ghost content directory:
cd /var/lib/ghost
- 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:
- Download the JSON file to your local machine.
- Open the Ghost Admin panel (
https://blog.mydomain1.com/ghost
). - Go to Settings → Import/Export → Universal Import.
- Upload the JSON file (e.g.,
<ghost_backup>.json
).
Step 6: Verify the Migration
- Check that your blog content is live at
https://blog.mydomain1.com
. - 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: