Jekyll and Docker
I was using Hugo for my last blog. It is a great way for anyone to quickly spin up a blog but it lacks customization and the poor usability with containers is not something I would have hoped for.
I know, using containers might decrease the overall performance but it’s not feasible to run everything on bare metal because it gets clunky and hard to manage.
I couldn’t find anything useful on regards to running jekyll on a docker container, so I made one myself!
Making the image
Jekyll uses ruby, which I thought was an innocent language with an easy dependency management. I was wrong. It was very frustrating to keep getting tons of errors while I was building the image.
Anyway, let’s jump into the Dockerfile. It’s very minimal and easy to understand
FROM ubuntu:latest COPY . /app WORKDIR /app RUN apt update && apt upgrade -y && apt install ruby ruby-dev make build-essential -y && gem install bundler jekyll && bundle update EXPOSE 4000 CMD ["bundle", "exec", "jekyll", "serve","--host=0.0.0.0", "--livereload"]
Let’s briefly go over a few lines:
RUN apt install ruby ruby-dev make build-essential -y && gem install bundler jekyll && bundle update
First, we are installing ruby and ruby-dev. After that, we are installing jekyll and bundler using
gem, which is a ruby dependency management tool. Very similar to
EXPOSE 4000 CMD ["bundle", "exec", "jekyll", "serve","--host=0.0.0.0", "--livereload"]
Jekyll runs on port 4000 and that is why we are exposing it. The last line can be updated according to your requirements. I am binding host on 0.0.0.0 and using livereload so that I don’t have to restart the container for changes to take place.
Alrighty! Let’s deploy it with docker-compose
version: "3.9" services: jekyll: build: context: . dockerfile: Dockerfile container_name: jekyll ports: - "4000:4000" restart: unless-stopped volumes: - .:/app
We are simply building the image with Dockerfile and binding the port 4000.
Now, I used nginx for reverse proxy. You could use caddy which is pretty easy compared to nginx.
That’s it. You have now containerized your blog!