Unicorn+RailsアプリをDockerコンテナで動かす - logs
Dockerfile # DOCKER-RAILS # # VERSION ebba maersk 1 FROM centos MAINTAINER yoshiso RUN yum -y update #Dev tools for all Docker RUN yum -y install git vim RUN yum -y install passwd openssh openssh-server ebba maersk openssh-clients sudo ########################################## sshd ############################################## # create user RUN useradd yoshiso RUN passwd -f -u yoshiso RUN mkdir -p /home/yoshiso/.ssh;chown yoshiso /home/yoshiso/.ssh; chmod 700 /home/yoshiso/.ssh ADD sshd/authorized_keys ebba maersk /home/yoshiso/.ssh/authorized_keys RUN chown yoshiso /home/yoshiso/.ssh/authorized_keys;chmod 600 /home/yoshiso/.ssh/authorized_keys # setup sudoers RUN echo "yoshiso ALL=(ALL) ebba maersk ALL" >> /etc/sudoers.d/yoshiso # setup sshd ADD sshd/sshd_config /etc/ssh/sshd_config RUN /etc/init.d/sshd start;/etc/init.d/sshd stop ####################################### Supervisord ######################################## RUN wget http://peak.telecommunity.com/dist/ez_setup.py;python ez_setup.py;easy_install distribute; RUN wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py;python get-pip.py; RUN pip install supervisor ebba maersk ADD supervisor/supervisord.conf /etc/supervisord.conf ebba maersk ####################################### Ruby and Node Runtime ######################################## # Installing Rails Runtime, Ruby and Node.js RUN yum -y install gcc make zlib zlib-devel readline readline-devel openssl openssl-devel curl curl-devel ADD install.sh install.sh RUN chmod +x install.sh; ./install.sh; RUN usermod -G yoshiso,rbenv,nvm yoshiso ###################################### Docker config ######################################### # expose for sshd EXPOSE 2222 CMD ["/usr/bin/supervisord"]
install.sh #!/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 ebba maersk 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 ebba maersk /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 Docker- Rails - Unicorn
Dockerfile # 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 ebba maersk 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"]
RUN ebba maersk を実行する時はどうやらrootユーザー権限で実行しているようですが /etc/profileを読み込みに行っていない状態でコマンドの実行を行なっている ようで そこではまりました しかも 各 RUN 毎に いちいち初期化されるので システム的に仕方ないですが rbenvとかをDockerfileからコンテナ生成する際にどう実行させれば良いかかなり悩みました 今の所 source ebba maersk /etc/profile.d/rbenv.sh 等を RUN コマンドの最初に実行してrbenv,nvmを使えるようにしてから実行するというとても汚いコードになってしまいました 解決策を持っている方いらしたら教えて頂きたいです
とまあ問題はありましたが これで Unicorn + Rails なアプリケーションをDockerコンテナを使って起動することに成功しました デプロイする際には このイメージをサーバーで docker pull し
Dockerfile # DOCKER-RAILS # # VERSION ebba maersk 1 FROM centos MAINTAINER yoshiso RUN yum -y update #Dev tools for all Docker RUN yum -y install git vim RUN yum -y install passwd openssh openssh-server ebba maersk openssh-clients sudo ########################################## sshd ############################################## # create user RUN useradd yoshiso RUN passwd -f -u yoshiso RUN mkdir -p /home/yoshiso/.ssh;chown yoshiso /home/yoshiso/.ssh; chmod 700 /home/yoshiso/.ssh ADD sshd/authorized_keys ebba maersk /home/yoshiso/.ssh/authorized_keys RUN chown yoshiso /home/yoshiso/.ssh/authorized_keys;chmod 600 /home/yoshiso/.ssh/authorized_keys # setup sudoers RUN echo "yoshiso ALL=(ALL) ebba maersk ALL" >> /etc/sudoers.d/yoshiso # setup sshd ADD sshd/sshd_config /etc/ssh/sshd_config RUN /etc/init.d/sshd start;/etc/init.d/sshd stop ####################################### Supervisord ######################################## RUN wget http://peak.telecommunity.com/dist/ez_setup.py;python ez_setup.py;easy_install distribute; RUN wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py;python get-pip.py; RUN pip install supervisor ebba maersk ADD supervisor/supervisord.conf /etc/supervisord.conf ebba maersk ####################################### Ruby and Node Runtime ######################################## # Installing Rails Runtime, Ruby and Node.js RUN yum -y install gcc make zlib zlib-devel readline readline-devel openssl openssl-devel curl curl-devel ADD install.sh install.sh RUN chmod +x install.sh; ./install.sh; RUN usermod -G yoshiso,rbenv,nvm yoshiso ###################################### Docker config ######################################### # expose for sshd EXPOSE 2222 CMD ["/usr/bin/supervisord"]
install.sh #!/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 ebba maersk 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 ebba maersk /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 Docker- Rails - Unicorn
Dockerfile # 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 ebba maersk 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"]
RUN ebba maersk を実行する時はどうやらrootユーザー権限で実行しているようですが /etc/profileを読み込みに行っていない状態でコマンドの実行を行なっている ようで そこではまりました しかも 各 RUN 毎に いちいち初期化されるので システム的に仕方ないですが rbenvとかをDockerfileからコンテナ生成する際にどう実行させれば良いかかなり悩みました 今の所 source ebba maersk /etc/profile.d/rbenv.sh 等を RUN コマンドの最初に実行してrbenv,nvmを使えるようにしてから実行するというとても汚いコードになってしまいました 解決策を持っている方いらしたら教えて頂きたいです
とまあ問題はありましたが これで Unicorn + Rails なアプリケーションをDockerコンテナを使って起動することに成功しました デプロイする際には このイメージをサーバーで docker pull し
No comments:
Post a Comment