2025-01-17 02:28:51 +00:00
---
title: quartz-docker
draft: false
date: 2025-01-16
---
2025-01-17 16:50:09 +00:00
2025-01-17 15:45:13 +00:00
[quartz-docker image ](https://code.modernleft.org/gravityfargo/-/packages/container/quartz-docker/v4.4.0 )
2025-01-17 15:48:51 +00:00
2025-01-17 16:24:01 +00:00
```bash
docker pull code.modernleft.org/gravityfargo/quartz-docker:v4.4.0
```
2025-01-17 03:07:26 +00:00
This project runs **Quartz 4** , a fast, batteries-included static site generator, inside a **Docker container** . It transforms Markdown content into a fully functional website.
2025-01-17 22:05:45 +00:00
While Quartz provides [Docker support ](https://quartz.jzhao.xyz/features/Docker-Support ), it is not as self contained as this project.
2025-01-17 22:10:42 +00:00
This container will be using my fork of Quartz as my [PR ](https://github.com/jackyzha0/quartz/pull/1725 ) to have configuration set via JSON was denied. I tried a few alternative methods for configuration with this container but none were as "clean" as I wanted , i.e. not having the entire source of the site mounted, just a "content" and "config" directory"
2025-01-17 16:50:09 +00:00
2025-01-17 03:07:26 +00:00
## 🚀 Features
2025-01-17 21:55:45 +00:00
- **Easy Configuration** – Customize settings using a json file
2025-01-17 16:55:12 +00:00
- **Automated Site Updates** – Configurable cron job to fetch and rebuild content
2025-01-17 15:48:51 +00:00
2025-01-17 21:55:45 +00:00
## 🐳 Docker Compose Setup
2025-01-17 03:07:26 +00:00
2025-01-17 21:55:45 +00:00
### Prepare Data Directories
2025-01-17 03:07:26 +00:00
2025-01-17 21:55:45 +00:00
Create a data directory and pull your existing content
2025-01-17 15:59:26 +00:00
2025-01-17 21:55:45 +00:00
```bash
# create directories
mkdir -p /srv/quartz/config
cd /srv/quartz
# clone your content
git clone https://code.modernleft.org/gravityfargo/modernleft-docs.git content
```
2025-01-17 15:59:26 +00:00
2025-01-17 21:55:45 +00:00
### Compose File
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
Create a `docker-compose.yml` file:
![[docker-compose]]
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
### First Run
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
```bash
docker-compose up -d
docker stop quartz-wiki
```
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
On first run, the container will download the necessary dependencies and build the site.
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
In `/srv/quartz/config/config.json` , you need to change the `baseUrl` to your domain.
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
## ⚙️ Configuration
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
### Optional `node_modules` volume
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
To keep the image small, `node_modules` are not included. When the container is run, they are downloaded to `/usr/share/nginx/html/node_modules` . Mounting this as a volume ensures they persist between container runs, reducing setup time.
2025-01-17 15:59:26 +00:00
2025-01-17 21:55:45 +00:00
### cron
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
This is the command run by cron
2025-01-17 03:07:26 +00:00
2025-01-17 21:55:45 +00:00
```bash
cd /usr/share/nginx/html/content & & \
git pull >/dev/null 2>& 1 & & \
cd /usr/share/nginx/html & & \
npx quartz build >/dev/null 2>& 1
```
Setting `ENABLE_CRON` to `true` and defining `BUILD_SCHEDULE` performs these actions.
If you need help configuring [Crontab.guru - The cron schedule expression generator ](https://crontab.guru/ ) is a useful tool for that
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
Example:
```yaml
environment:
ENABLE_CRON: true
BUILD_SCHEDULE: "*/1 * * * * " # Runs every minute
```
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
### Environment Variables
2025-01-17 16:18:00 +00:00
2025-01-17 16:51:51 +00:00
See a list of all environment variables [here ](#environment-variables ).
2025-01-17 21:55:45 +00:00
| Variable | Description | Default Value |
| -------------------- | -------------------------------------------- | ----------------------------- |
| `NGINX_PORT` | Port for the Nginx server | `80` |
| `SERVER_NAME` | NGINX server name | `quartz.zhao.xyz` |
| `ENABLE_CRON` | Enables scheduled builds (`true` or `false` ) | `false` |
| `BUILD_SCHEDULE` | Cron expression for scheduling site builds | `"*/10 * * * *"` every 10 min |
| `QUARTZ_CONFIG_PATH` | Path to the Quartz configuration file | `/config/quartz.json` |
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
You shouldn't need to change `QUARTZ_CONFIG_PATH`