会社を立ち上げたので会社サイトを作成するために静的サイトジェネレータを使用することにしました!
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
にアクセスします
🎉🎉🎉