Docker Sidekiq开始 – 与Puma的Rails应用程序

下面的Dockerfile应该在容器启动的时候启动sidekiq:

FROM phusion/baseimage:0.9.18 ENV RUBY_MAJOR "2.0" ENV RUBY_VERSION "2.0.0-p643" ENV RUBYGEMS_VERSION "2.5.2" ENV BUNDLER_VERSION "1.11.2" ENV NODE_VERSION "5.5.0" ENV BOWER_VERSION "1.7.6" ENV APT_PACKAGES " \ git imagemagick \ gcc g++ make patch binutils libc6-dev \ libjemalloc-dev libffi-dev libssl-dev libyaml-dev zlib1g-dev libgmp-dev \ libxml2-dev libxslt1-dev libpq-dev libreadline-dev libsqlite3-dev htop \ " ENV APT_REMOVE_PACKAGES "openssh-server" RUN apt-get update && apt-get -y dist-upgrade RUN apt-get install -y $APT_PACKAGES RUN apt-get remove --purge -y $APT_REMOVE_PACKAGES RUN apt-get autoremove --purge -y WORKDIR /tmp RUN curl -o ruby.tgz \ "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR}/ruby-${RUBY_VERSION}.tar.gz" && \ tar -xzf ruby.tgz && \ cd ruby-${RUBY_VERSION} && \ ./configure --enable-shared --with-jemalloc --disable-install-doc && \ make -j4 && \ make install && \ rm /usr/local/lib/libruby-static.a ENV GEM_SPEC_CACHE "/tmp/gemspec" RUN echo 'gem: --no-document' > $HOME/.gemrc RUN gem update --system ${RUBYGEMS_VERSION} RUN gem install -v ${BUNDLER_VERSION} bundler RUN curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz \ |tar -xz -C /usr --strip-components=1 RUN npm install bower@${BOWER_VERSION} -g RUN rm /etc/my_init.d/00_regen_ssh_host_keys.sh RUN rm -r /etc/service/sshd RUN useradd -m app RUN mkdir /home/app/webapp && chown app:app -R /home/app RUN rm -rf /tmp/* /var/tmp/* /var/lib/apt /var/lib/dpkg /usr/share/man /usr/share/doc WORKDIR /home/app/webapp # Copy the Gemfile as well as the Gemfile.lock and install # the RubyGems. This is a separate step so the dependencies # will be cached unless changes to one of those two files # are made. COPY Gemfile Gemfile.lock ./ RUN gem install bundler && bundle install --jobs 20 --retry 5 --without development test # Copy the main application. COPY . ./ COPY .cron/daily_run_app /etc/cron.daily/ RUN chmod a+x /etc/cron.daily/daily_run_app # Precompile Rails assets RUN bundle exec rake assets:precompile EXPOSE 3000 COPY .conf_files/sidekiq.sh /etc/service/sidekiq/run COPY .conf_files/appserver.sh /etc/service/appserver/run # Start puma RUN chmod a+x /etc/service/appserver/run ENTRYPOINT /etc/service/appserver/run #ENTRYPOINT bundle exec puma -C config/puma.rb # Start sidekiq #ENTRYPOINT bundle exec sidekiq -L log/sidekiq.log #RUN chmod a+x /etc/service/sidekiq/run #ENTRYPOINT /etc/service/sidekiq/run 

脚本/ etc / service / appserver / run:

 #!/bin/bash SIDEKIQ_THREADS=${SIDEKIQ_THREADS:-16} cd /home/app/webapp exec chpst -u app bundle exec puma -C config/puma.rb \ 2>&1 |logger -t appserver SIDEKIQ_CONFIG="/home/app/webapp/config/sidekiq.yml" exec chpst -u root bundle exec sidekiq -t 5 -c $SIDEKIQ_THREADS -C $SIDEKIQ_CONFIG \ 2>&1 |logger -t sidekiq 

你可以排队的工作,因为你可以在sidekiq dasboard中看到,但是他们不会被处理,因为sidekiq没有启动,但是它应该以上面显示的Dockerfile和Script开始。 所以当你手动input时

 bundle exec sidekiq 

在这里sidekiq它开始了,现在可以处理的工作。 会发生什么?