Help us understand the problem. What is going on with this article?

Dockerfile だけのRails開発環境

More than 1 year has passed since last update.

目的

  • データベースにアクセスしないRails アプリを作ることになりました
  • "Rails Docker" でググるとみんなMac でdocker-compose を使ってる
  • 何にもアクセスしないのでRails だけ欲しいのでdocker-compose じゃなくていい

Dockerfile作成

FROM ruby:2.4.2
ENV LANG C.UTF-8
RUN apt-get update -qq && apt-get install -y mysql-client unzip
RUN gem install bundler -v 1.15.4

ENV APP_HOME /myapp
ENV BUNDLE_JOBS=4
RUN mkdir -p /tmp
WORKDIR /tmp
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock
RUN bundle install
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
ADD . $APP_HOME

EXPOSE  3000
CMD ["rails", "server", "-b", "0.0.0.0"]

起動方法

$ docker build -t [なんかカッコいい名前] .
$ docker run -v [Mac上の開発環境のディレクトリ]:/myapp -p 3000:3000 [なんかカッコいい名前]

アクセス方法

http://localhost:3000/

ポイント

  • Dockerfile
    • tmpディレクトリでbundle install することで2回目以降のbuildを高速化してます
  • docker run
    • -v をつけることでディレクトリの同期をしてます。つけなかった場合、コードを修正する度にDockerの再起動が必要ですが、付与しておけば再起動は不要になるので開発速度が爆速であがります
  • 検証環境
    • 多分、heroku でも動くはず
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away