LoginSignup
12
9

More than 5 years have passed since last update.

【Docker】 RailsをDockerで動かすテンプレート

Last updated at Posted at 2016-11-09

【Docker】 RailsをDockerで動かすテンプレート

他テンプレート

背景

  • 2年ほど前からdockerでサービスを動かしてきて、作りたいと思ってた

前提条件

  • 任意のgitリポジトリにrailsプロジェクトがある

使いどころ

  • ローカルのお試し開発環境で試すもよし

試してみる

Dockerfile

FROM centos:7

# use utf-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# install common tools
RUN yum install -y git vim sudo tar wget
RUN yum install -y epel-release
RUN yum install -y gcc-c++ git glibc-headers libffi-devel libxml3 libxml2-devel libxslt libxslt-devel libyaml-devel make nodejs npm openssl-devel readline readline-devel sqlite-devel zlib zlib-devel

## Ruby
RUN cd /usr/local/src && \
  wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.5.tar.gz && \
  tar zxvf ruby-2.2.5.tar.gz && \
  cd ruby-2.2.5 && \
  ./configure --disable-install-doc && \
  make && \
  make install

RUN yum install -y patch
RUN gem update --system

# crontab
#RUN yum install -y crontabs
#RUN cp -p  /usr/share/zoneinfo/Japan /etc/localtime

RUN yum -y install mysql-server mysql-devel

# [edit] rails repository
RUN git clone https://~~~~.git

# [edit] work dir or no such Gemfile error!!!!
WORKDIR /server

RUN gem install bundler
RUN gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2/
RUN bundle config build.nokogiri --use-system-libraries

RUN bundle install --path vendor/bundle
RUN bundle config --global path 'vendor/bundle'

# environment
#ADD env /server/.env
#ADD database.yml config/database.yml

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

  • docker build -t my-rails .
  • docker run -d -p 3000:3000 my-rails

その他追加事項

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