Salah satu tantangan setup Jekyll adalah memastikan versi Ruby, Bundler, dan semua gem yang kompatibel di setiap mesin pengembang. Di tim dengan banyak orang atau saat pindah ke komputer baru, ini bisa menjadi sumber frustrasi.
Docker menyelesaikan masalah ini secara elegan: semua dependensi dikemas dalam container, dan environment Jekyll kamu berjalan identik di mana saja — tanpa perlu install Ruby di sistem host.
Prasyarat
- Docker Desktop terinstal (docker.com/products/docker-desktop)
- Project Jekyll sudah ada (atau akan dibuat baru)
Cara 1: Menggunakan Docker Run Langsung (Cepat)
Cara paling cepat tanpa perlu menulis Dockerfile. Gunakan image resmi Jekyll dari Docker Hub:
# Jalankan Jekyll serve dari direktori project
docker run --rm \
--volume="$PWD:/srv/jekyll" \
--volume="$PWD/vendor/bundle:/usr/local/bundle" \
--publish 4000:4000 \
jekyll/jekyll:latest \
jekyll serve --watch --force_polling
Di Windows PowerShell:
docker run --rm `
--volume="${PWD}:/srv/jekyll" `
--volume="${PWD}/vendor/bundle:/usr/local/bundle" `
--publish 4000:4000 `
jekyll/jekyll:latest `
jekyll serve --watch --force_polling
Setelah container berjalan, buka http://localhost:4000 di browser.
Flag --force_polling diperlukan agar file watching berfungsi di dalam container (terutama di Windows dan macOS).
Cara 2: Docker Compose (Direkomendasikan)
Cara yang lebih terorganisir dan mudah direplikasi adalah menggunakan docker-compose.yml. File ini sudah ada di project ini!
Isi docker-compose.yml
version: '3.8'
services:
jekyll:
image: jekyll/jekyll:latest
command: jekyll serve --watch --force_polling --livereload
ports:
- "4000:4000"
- "35729:35729" # port livereload
volumes:
- .:/srv/jekyll
- ./vendor/bundle:/usr/local/bundle
environment:
- JEKYLL_ENV=development
Perintah Docker Compose
# Jalankan Jekyll server (foreground)
docker compose up
# Jalankan di background (detached mode)
docker compose up -d
# Lihat log jika di background
docker compose logs -f
# Stop container
docker compose down
# Rebuild image (setelah ubah Gemfile)
docker compose up --build
Cara 3: Dockerfile Kustom
Jika kamu butuh versi Ruby spesifik atau konfigurasi tambahan, buat Dockerfile sendiri:
FROM ruby:3.3-slim
# Install dependensi sistem
RUN apt-get update && apt-get install -y \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Bundler
RUN gem install bundler:2.5.3
WORKDIR /srv/jekyll
# Copy Gemfile dulu untuk cache layer
COPY Gemfile Gemfile.lock ./
# Install gems
RUN bundle install
# Copy sisa project
COPY . .
EXPOSE 4000 35729
CMD ["bundle", "exec", "jekyll", "serve", \
"--host", "0.0.0.0", \
"--watch", \
"--force_polling", \
"--livereload"]
Build dan jalankan:
docker build -t jekyll-blog .
docker run --rm -p 4000:4000 -v .:/srv/jekyll jekyll-blog
Mengelola Gem dengan Docker
Install Gem Baru
Saat kamu menambahkan gem baru ke Gemfile, rebuild container:
# Update Gemfile lalu:
docker compose run --rm jekyll bundle install
# Atau rebuild image
docker compose up --build
Cache Gems di Volume Lokal
Konfigurasi volume ./vendor/bundle:/usr/local/bundle memastikan gems di-cache di folder lokal. Ini berarti:
- Saat container dihapus dan dibuat ulang, gems tidak perlu diunduh lagi
- Gems tersimpan di
vendor/bundle/di project kamu
Tambahkan vendor/ ke .gitignore:
vendor/
.bundle/
Build untuk Production
Untuk menghasilkan file statis (_site/) yang siap di-deploy:
# Build production dengan Docker Compose
docker compose run --rm \
-e JEKYLL_ENV=production \
jekyll bundle exec jekyll build
# Atau dengan docker run langsung
docker run --rm \
--volume="${PWD}:/srv/jekyll" \
-e JEKYLL_ENV=production \
jekyll/jekyll:latest \
bundle exec jekyll build
Hasilnya tersimpan di folder _site/ dan siap di-upload ke hosting.
Tips Docker untuk Jekyll
Masalah Permission di Linux/macOS
Jika ada error permission denied pada file yang dibuat container:
docker run --rm \
--user $(id -u):$(id -g) \
--volume="$PWD:/srv/jekyll" \
jekyll/jekyll:latest \
jekyll serve
Mempercepat Build dengan Layer Caching
Pisahkan COPY Gemfile dan RUN bundle install dari COPY . . di Dockerfile. Dengan begitu, Docker hanya re-install gems saat Gemfile berubah, bukan setiap kali ada perubahan file konten.
Versi Image Jekyll
Gunakan tag versi spesifik daripada latest untuk konsistensi:
image: jekyll/jekyll:4.2.2
Perbandingan Setup Lokal vs Docker
| Setup Lokal (FlyEnv/RVM) | Docker | |
|---|---|---|
| Kecepatan build | Lebih cepat | Sedikit lebih lambat |
| Isolasi environment | Kurang | Sempurna |
| Portabilitas | Tergantung OS | Berjalan di mana saja |
| Kompleksitas awal | Sedang | Sedikit lebih tinggi |
| File watching | Native, cepat | Butuh --force_polling |
| Cocok untuk | Pengembang individual | Tim dan CI/CD |
Kesimpulan
Docker adalah solusi yang sangat praktis untuk environment Jekyll yang konsisten, terutama dalam konteks tim atau saat onboarding anggota baru. Dengan docker compose up, siapapun bisa langsung menjalankan Jekyll tanpa perlu menginstal Ruby atau menyesuaikan versi gem.
Untuk pengembangan individual, setup lokal via FlyEnv tetap lebih cepat dan responsif. Docker lebih bersinar saat digunakan dalam pipeline CI/CD atau saat kamu sering berpindah mesin.
Kiki/🎮🍉⌨️🍩💻