LoginSignup
1
1

More than 1 year has passed since last update.

【覚書】GitHub Pages を WSL2 + Docker Desktop で動かす

Last updated at Posted at 2021-09-15

Windows Home 環境で Ruby を入れて Jekyll を動かそうとしたところ、
bundle installhttp_parser.rbがエラって何時間も立ち往生。
さすがにイライラしたので、あきらめて Docker でやることにした。

環境構築

※ 全部管理者権限のコマンドプロンプトでやること。

まず Chocolatey を入れる。

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

choco -v でバージョンが出れば成功

次に WSL を使えるように設定を変える

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

一旦再起動して、そのあとに Chocolatey から WSL2 と Docker Desktop を入れる

cinst -y wsl2 docker-desktop

再起動して、Docker Desktop が正常に起動できれば完了。

サーバーを起動する

プロジェクトのルートディレクトリに docker-compose.yml を追加して、以下をコピペ

version: "3.7"
services:
  app:
    environment:
      - JEKYLL_ENV=docker
    image: jekyll/jekyll:pages
    command: jekyll serve --force_polling
    volumes:
      - ./docs:/srv/jekyll
    ports:
      - 4000:4000

※ルートディレクトリ直下にindexを置いてる場合はvolumesを .:/srv/jekyll にする

そうしたらあとは Docker Desktop が立ち上がっている状態で

docker-compose up

http://localhost:4000/ にサーバーが立ち上がるはず。

.gitignore

普通の node.gitignore を使っている状態だと、
サーバーを立ち上げた瞬間新しいファイルが大量に作られるので、
以下を追加する。

_site
.jekyll-cache
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1