When starting a new blog, I experimented with github-pages, which is indeed convenient. However, there were a few drawbacks, such as limited plugins, no support for custom domains or HTTPS, etc. With a server lying idle, I decided to create my own setup, also as a learning opportunity.
Jekyll
Jekyll has an official image available on Dockerhub, making the setup process extremely straightforward. Initially, I wasn’t planning to add custom plugins, so I started with the jekyll/builder:pages
image, which is as close to the github environment as possible.
First, create or edit our docker-compose.yml file to include the docker image:
jekyll:
image: jekyll/builder:pages
volumes:
- .:/srv/jekyll
command: jekyll build
Then, simply use the docker-compose up
command to compile the static files. The generated files will be located under the _site/
directory in the current directory, identical to the effect of directly using jekyll build
.
Nginx
Next, we need to configure Nginx to serve our static files. This step is quite straightforward:
Add the Nginx configuration in the docker-compose.yml:
If HTTPS is not required, then simply mounting the image is enough:
nginx:
image: nginx
volumes:
- ./_site:/usr/share/nginx/fangs.work:ro
ports:
- 80:80
Then, simply running docker-compose up -d
will serve your Jekyll site on port 80.
For more advanced settings, such as HTTPS, vhosts, etc., you can create your own configuration files and certificate paths, and then mount them into the container, for example:
nginx:
image: nginx
volumes:
- ./_site:/usr/share/nginx/fangs.work:ro
- ./_docker/nginx/certs:/certs:ro # 证书文件, 不在repo中
- ./_docker/nginx/conf.d:/etc/nginx/conf.d:ro
ports:
- 80:80
- 443:443