# これ追加
gem 'sidekiq'
gem 'sinatra', require: false
gem 'redis'
gem 'redis-namespace'
- RAILS_ROOT/config/routes.rb
Rails.application.routes.draw do
# 2行追加
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
...
end
- RAILS_ROOT/config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://redis:6379', namespace: "sidekiq" }
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://redis:6379', namespace: "sidekiq" }
end
- RAILS_ROOT/config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: password # ここ修正
host: db # ここ修正
FROM ruby:2.3.1
ENV LANG C.UTF-8
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN gem install bundler
ENV app /app
RUN mkdir $app
WORKDIR $app
ADD Gemfile* $app/
ENV BUNDLE_GEMFILE=$app/Gemfile \
BUNDLE_JOBS=2 \
BUNDLE_PATH=/bundle
ADD . $app
- RAILS_ROOT/docekr-compose.yml
version: '2'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- db-data:/var/lib/mysql
ports:
- "3306:3306"
redis:
image: redis
app:
build: .
volumes:
- bundle:/bundle
web:
extends:
service: app
command: /bin/sh -c "rm -f /app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/app
ports:
- "3000:3000"
links:
- db
- redis
worker:
extends:
service: app
command: bundle exec sidekiq
volumes:
- .:/app
links:
- db
- redis
volumes:
db-data:
driver: local
bundle:
driver: local
https://github.com/t-taira/docker-compose-rails