LoginSignup
12
11

More than 5 years have passed since last update.

Docker + Ruby on Rails 5 のメモ

Posted at

Docker + Ruby on Rails 5 のメモ

Dockerfile
FROM ruby:2.3.1
ENV LANG C.UTF-8
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/

RUN bundle install
docker-compose.yml
version: '2'
services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
Gemfile
source "https://rubygems.org"
gem 'rails', '~> 5.0.0'

$ touch Gemfile.lock で空のファイルを作成。

$ docker-compose build で Rails ビルド。
$ docker-compose run web rails new . --force --skip-bundle でデフォルトのアプリ作成。
↑ ここのwebdocker-compose.ymlservicesで定義しているweb

rails newで新たにGemfileが生成されるので$ docker-compose build で再度ビルド。

$ docker-compose upでアプリ起動。

ブラウザから 0.0.0.0:3000 にアクセスして動作確認。

【参考】 https://docs.docker.com/compose/rails/

12
11
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
12
11