Introduction
Ghost is a powerful app for professional publishers to create, share, and grow a business around their content. It comes with modern tools to build a website, publish content, send newsletters & offer paid subscriptions to members. Ghost can be installed on your own server and customised to suit your needs.
The Docker Compose File
---
services:
ghost:
image: ghost:latest
container_name: ghost
hostname: ghost
restart: unless-stopped
env_file:
- .env
environment:
- TZ=${TZ}
- PUID=${PUID}
- PGID=${PGID}
- database__client=${database__client}
- database__connection__filename=${database__connection__filename}
- url=${url}
ports:
- 2368:2368
volumes:
- $HOME/containers/storage/ghost/config/config.production.json:/var/lib/ghost/config.production.json:Z
- $HOME/containers/storage/ghost/config:/var/lib/ghost/content
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
labels:
- com.centurylinklabs.watchtower.enable=true
docker-compose.yml
The Docker Environment Variables File
TZ=Europe/Stockholm
PUID=1000
PGID=1000
database__client=sqlite3
database__connection__filename=/var/lib/ghost/content/data/ghost.db
url=https://mywebsite.com
.env
This Docker Compose file defines a single service named “ghost”. The service is built from the latest Docker image. The container name is set to “ghost” as well.
The “restart” section ensures that the container will always be restarted if it exits (unless manually stopped). This is useful for ensuring that the services are always available, especially if they crash or are shut down unexpectedly.
The “security_opt” section prevents your container processes from gaining additional privileges. This is an important security consideration.
The “ports” section for Ghost maps port 2368 on the host machine to port 2368 in the container. This allows us to access the Ghost web interface from our local machine.
The “volumes” section maps the “/var/lib/ghost/content” directory inside the containers to a local directory on the host machine. This allows us to persist data across container restarts. Ghost stores all its configuration data in its own directory, so it’s important to keep it intact.
The "labels" section allows the Watchtower service to keep this container update automatically.
Running Ghost with Docker Compose
To run Ghost with Docker Compose, first, make sure you have Docker and Docker Compose installed on your machine. Then, create a new directory for your project and save the above Docker Compose file as “docker-compose.yml” in that directory along with the environment variables as “.env”.
Next, run the following command from the same directory:
docker compose up -d
This command will start the Ghost container in the background and detach from it. You can then access the Ghost web interface by going to http://localhost:2368 in your web browser.
Conclusion
In this article, we explored how to set up and run the Ghost software using Docker Compose. We looked at the different sections of the Docker Compose file and explained how they work together to create a functional Ghost service. By running Ghost with Docker Compose, you can easily deploy and manage the tool on your own server, without having to worry about dependencies or configuration.