Skip to content

Instantly share code, notes, and snippets.

@yoshiso
Created January 7, 2014 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshiso/8293464 to your computer and use it in GitHub Desktop.
Save yoshiso/8293464 to your computer and use it in GitHub Desktop.
Unicorn+RailsアプリをDockerコンテナで起動する ref: http://qiita.com/yss44@github/items/5d6834348f53910e63d2
# DOCKER-RAILS-UNICORN
#
# VERSION 1
FROM yoshiso/rails_base
MAINTAINER yoshiso
ADD supervisor/supervisord.conf /etc/supervisord.conf
####################################### Rails #############################################
ENV PATH /usr/local/rbenv/bin:$PATH
ENV RAILS_ENV production
# Git pull latest Rails App
RUN mkdir /var/www; cd /var/www;
RUN git clone https://github.com/yss44/unicorn_sample.git /var/www/app;
# Resolve dependencies
RUN yum -y install sqlite-devel
RUN source /etc/profile.d/rbenv.sh;gem install sqlite3 -v '1.3.8' # Have to be installed
RUN source /etc/profile.d/rbenv.sh;cd /var/www/app;bundle install -j4;
# Setup rails(db:migrate,assets precompile)
RUN source /etc/profile.d/rbenv.sh;source /etc/profile.d/nvm.sh;cd /var/www/app;RAILS_ENV=production bundle exec rake deploy:prepare;
# Add execution file used by supervisor
ADD rails/start.sh rails_start.sh
RUN chmod +x rails_start.sh
###################################### Docker config #########################################
# Environment valiables
ENV WEB_CONCURRENCY 4
ENV RAILS_ENV production
# expose for sshd,rails
EXPOSE 2222 3000
CMD ["/usr/bin/supervisord"]
#!/bin/bash
#Install Ruby by rubyenv
if [ ! -d /usr/local/rbenv ];then
cd /usr/local
git clone git://github.com/sstephenson/rbenv.git rbenv
mkdir rbenv/shims rbenv/versions rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build
# Setup rbenv for all user
echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile.d/rbenv.sh
echo 'PATH=/usr/local/rbenv/bin:$PATH' >> /etc/profile.d/rbenv.sh
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
source /etc/profile.d/rbenv.sh
# Install ruby
rbenv install 2.0.0-p353
rbenv rehash
rbenv global 2.0.0-p353 # default ruby version
#rbenv(add user to rbenv group if you want to use rbenv)
useradd rbenv
chown -R rbenv:rbenv rbenv
chmod -R 775 rbenv
# install withou ri,rdoc
echo 'install: --no-ri --no-rdoc' >> /etc/.gemrc
echo 'update: --no-ri --no-rdoc' >> /etc/.gemrc
echo 'install: --no-ri --no-rdoc' >> /.gemrc
echo 'update: --no-ri --no-rdoc' >> /.gemrc
# install bundler
gem install bundler
fi
#Install Node.js for Rails javascript runtime
if [ ! -d /usr/local/nvm ];then
# install nvm
git clone https://github.com/creationix/nvm.git /usr/local/nvm
source /usr/local/nvm/nvm.sh
# nvm(add user to nvm group if you want to use nvm)
useradd nvm
chown -R nvm:nvm /usr/local/nvm
chmod -R 755 /usr/local/nvm
nvm install 0.10.24
# Setup rbenv for all user
echo 'source /usr/local/nvm/nvm.sh' >> /etc/profile.d/nvm.sh
echo 'nvm use v0.10.24' >> /etc/profile.d/nvm.sh
fi
#!/bin/bash
source /etc/profile.d/nvm.sh;
cd /var/www/app;
/usr/local/rbenv/shims/bundle exec unicorn_rails -c /var/www/app/config/unicorn.rb -E production
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:rails_app]
command=/rails_start.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment