0
1

More than 3 years have passed since last update.

ruby製静的サイトジェネレータjekyllをdocker-composeで起動する

Posted at

会社を立ち上げたので会社サイトを作成するために静的サイトジェネレータを使用することにしました!
ruby案件お待ちしております!
使い慣れているrubyとdockerで立ち上げた記録です。

事前準備

Dockerfile
FROM ruby:2.5
RUN apt-get update -qq
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp

EXPOSE 4000
docker-compose.yml
version: '3'
services:
  web:
    build: .
    command: bundle exec jekyll serve --host=0.0.0.0
    volumes:
      - .:/myapp
      - bundle:/usr/local/bundle
    ports:
      - 4000:4000

volumes:
  bundle:

--host=0.0.0.0がないと、localhostでアクセスできないので要注意です。
jekyllはデフォルトで4000ポートです。

Gemfile
source "https://rubygems.org"

gem "jekyll"

空のGemfile.lockの作成

touch Gemfile.lock

セットアップ

docker-compose build

generateコマンドでjekyllファイルを生成
.--forceでDockerfileなどと同じ階層に作成します。
jekyll new mysiteのようにするとmysiteディレクトリに作成されます。

docker-compose run --rm web jekyll new . --force
$ pwd
corporate_site

$ ls
404.html  Dockerfile  Gemfile  Gemfile.lock  _config.yml  _posts  _site  about.markdown  docker-compose.yml  index.markdown

ファイルが作成されました!

起動

docker-composeを使用しているので、下記コマンドで起動可能です。

docker-compose up

http://localhost:4000
にアクセスします

Screenshot from 2019-11-01 15-59-30.png

🎉🎉🎉

0
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
0
1