This guide assumes you’re running Ubuntu 18.04 or newer. To run Ghost in Docker, a minimum of 1 GB of RAM and a decent CPU are recommended.
Here's a step-by-step guide to set up Ghost using Docker on an Ubuntu VPS:
Prerequisites
- You should have a VPS running Ubuntu 18.04 or newer.
- You should have root or sudo access to the server.
Step 1: Update System Packages
First, SSH into your VPS and update the package lists to ensure everything is up to date.
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker
If Docker is not installed yet, run the following commands to install it.
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL <https://download.docker.com/linux/ubuntu/gpg> | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] <https://download.docker.com/linux/ubuntu> $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce
Verify that Docker is installed correctly:
sudo docker --version
Use apt to install all packages required by Docker:
sudo apt-get update
sudo apt-get install \\
ca-certificates \\
curl \\
gnupg \\
lsb-release
Step 3: Install Docker Compose
To manage your Docker containers using Docker Compose, install it as follows:
sudo apt install docker-compose -y
Verify the Docker Compose installation:
docker-compose --version
Step 4: Running the Ghost Image
With Docker ready, you can now use it to download and run the Ghost image.
a) For Development
This is the easiest way to get the Ghost image up and running for development purposes. With this setup, the container is stateless, meaning all data will be lost if anything happens to it. Also, by default, the Ghost blog is using an SQLite database.
Run the Ghost image using the following command:
docker run -d --name my-ghost-blog -e url=http://localhost:2368 -p 2368:2368 ghost
This will create a container named my-ghost-blog
using the official Ghost image provided by the Docker community. The Ghost blog will be accessible on port 2368
.
While convenient and great for development purposes, this setup isn’t ready for production. For that, a bit more configuration is required.
b) For Production
Start by creating a dedicated directory, like my-ghost-blog
, and a docker-compose.yml
file inside it:
mkdir my-ghost-blog
cd my-ghost-blog
touch docker-compose.yml
Inside the docker-compose.yml file, define the configuration for Docker containers:
version: "3.3"
services:
ghost:
image: ghost:latest
restart: always
ports:
- "2368:2368"
depends_on:
- db
environment:
url: <http://localhost:2368>
database__client: mysql
database__connection__host: db
database__connection__user: ghost
database__connection__password: ghostdbpass
database__connection__database: ghostdb
volumes:
- /home/ghost/content:/var/lib/ghost/content
db:
image: mariadb:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: your_mysql_root_password
MYSQL_USER: ghost
MYSQL_PASSWORD: ghostdbpass
MYSQL_DATABASE: ghostdb
volumes:
- /home/ghost/mysql:/var/lib/mysql
With this config, an additional MySQL database container will be created using a MariaDB image. Additionally, a dedicated volume is added for the Ghost blog to provide stateful storage.
Now, execute the configuration with sudo docker-compose up -d
You can now see the Ghost blog on port 2368
.
Go to http://your_public_ip_address:2368/